[英]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"
但是当我通过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.找不到日期“2022-05-10”,但我在数据库中输入了该日期的值。
Here is a screenshot of my Postman request:这是我的邮递员请求的屏幕截图:
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);
}
}
Check your route in api.php
it should be as:检查您在
api.php
中的路线,它应该是:
Route::get('/news/search/{dates}', [NewsController::class, 'getNewsDate']);
You have to slashes after api
by the way)顺便说一句,你必须在
api
之后斜线)
api//news/search
remove one of them.删除其中之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.