laravel find or fail exception

Solutions on MaxInterview for laravel find or fail exception by the best coders in the world

showing results for - "laravel find or fail exception"
Dilys
27 Jan 2020
1use Illuminate\Database\Eloquent\ModelNotFoundException;
2
3// Will return a ModelNotFoundException if no user with that id
4try
5{
6    $user = User::findOrFail($id);
7}
8// catch(Exception $e) catch any exception
9catch(ModelNotFoundException $e)
10{
11    dd(get_class_methods($e)); // lists all available methods for exception object
12    dd($e);
13}