【发布时间】:2018-11-06 18:48:56
【问题描述】:
响应对象为空时无法获得响应。当对象返回数据时完美运行。
public function show($id)
{
$associates = Associate::find_by_id($id);
if(count($associates)<1)
{
$output = array('message' => 'No Records Found');
$status = 204;
}
else{
$output = array('message' => 'success','data'=>$associates);
$status = 200;
}
return response()->json($output,$status);
}
$associate 对象为空时没有响应。 $associate 不为空时的响应:
{
"message": "success",
"data": [
{
"first_name": "xxx",
"last_name": "xxx",
"mobile": xxxxxxxxxx,
"email": "xxxxxx@xxxxx",
"city": "xxxxx",
"state": "xxxxxx",
"pincode": "xxxxx"
}
]
}
【问题讨论】:
-
尝试使用
Associate::find($id)而不是find_by_id -
@DerekPollard 我为此结果使用多个表的连接,我可以使用 Associate::find($id) 连接吗?
标签: laravel laravel-5.7 jsonresponse