newQuery(); $institute->wit-6ren">
gpt4 book ai didi

laravel - HTTP 状态代码 "0"无效

转载 作者:行者123 更新时间:2023-12-01 09:47:07 25 4
gpt4 key购买 nike

HTTP 状态代码“0”无效。

public function filter()
{
$institute = (new Institute)->newQuery();
$institute->with(['locations','courses' => function ($query) use ($request){
$query->with('trainers');
}]);
}
$data = $institute->get();
if(count($data) > 0)
{
return response()->json($data);
}
else
{
return response()->json(404,'No Data found');
}
}

实际上,如果没有数据,我想显示错误 404 消息,

我的问题是当我尝试检查数据是否存在时,我收到一个名为 InvalidArgumentException 的错误。请任何人帮忙解决这个问题。

最佳答案

return response()->json(404,'No Data found');

json 的第一个参数应该是数据,然后是状态码。在这种情况下,状态代码获得 0 值。只需按照以下步骤操作:
return response()->json('No Data found', 404);

关于laravel - HTTP 状态代码 "0"无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46362882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com