Laravel Json Response Not working as expected

前端 未结 3 1725
暖寄归人
暖寄归人 2021-01-28 19:09

Unable to get response while response object is empty. Works perfect when the object has data returned.

public function show($id)
{
    $associates = Associate::         


        
3条回答
  •  闹比i
    闹比i (楼主)
    2021-01-28 19:49

    It will be easier if you use route model binding to find the ID of the record. For more information check https://laravel.com/docs/5.7/routing#route-model-binding.

    I think the snippet below should work.

    if ($associates) {
        $output = array('message' => 'success','data'=>$associates);
        $status = 200;
    } else {
        $output = array('message' => 'No Records Found');
        $status = 204;
    }
    

提交回复
热议问题