Monday, March 6, 2017

Call to undefined method Illuminate\Http\JsonResponse::all()

I am getting this error

Call to undefined method Illuminate\Http\JsonResponse::all()

I am trying to create custom Exception in laravel 5.4

I was following this stackoverflow answer here: http://stackoverflow.com/qu...

Exception is getting caught, but I am not able to return anything

here is my code:

public function getTags($lessonId)
{
try{

$tags = Lesson::findOrFail($lessonId)->tags;

return $tags;

}
catch(ModelNotFoundException $e)
{
//dd('biscuit');

return response()->json([
'error' => ['message' => 'Resource not found']
]);

}

}

Inside the catch block, it is die and printing biscuit perfectly

but when i try to return json, it is throwing this error, Call to undefined method Illuminate\Http\JsonResponse::all()

I even tried keeping the return statement outside the catch block but of no use. still the same error.

if i try to return a simple string like

return 'not found';

I am getting this error Call to a member function all() on string

I am having a headache, any solution will be greatly appreciated.



via Michael Joshua

Advertisement