The HTTP status code "0" is not valid.
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');
}
}
Actually, I want to display error 404 message if there is no data,
my problem is when I try to check whether data is there or not I'm getting an error called InvalidArgumentException.Can anyone help on this please.
return response()->json(404,'No Data found');
The first argument of json should be data, then goes a status code. In this case the status code gets 0 value. Simply do it as follows:
return response()->json('No Data found', 404);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With