Search code examples
laravelapipostmanget-request

Pass a date as a get request on postman however i can't find data from database in laravel


I like to get my value when I pass the date in get a request. But when I pass http://127.0.0.1:8000/api//news/search/"2022-05-10"

date "2022-05-10" was not found but I entered the value of this date in the database.

Here is a screenshot of my Postman request:

enter image description here

Here is the controller:

public function getNewsDate($dates) {
    $news = News::where('date', $dates)->get();
    if ($news) {
        return response()->json($news, 200);
    } else {
        return response()->json('News not found', 404);
    }
}

Solution

  • Check your route in api.php it should be as:

    Route::get('/news/search/{dates}', [NewsController::class, 'getNewsDate']);
    

    You have two slashes after api by the way)

    api//news/search
    

    remove one of them.