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

Time:07-22

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);
    }
}

CodePudding user response:

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

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

You have to slashes after api by the way)

api//news/search

remove one of them.

  • Related