findOrFail

Submitted by bwsewell - 3 years ago

Handling findOrFail exceptions

// Will return a ModelNotFoundException if no user with that id
try
{
    $user = User::findOrFail($id);
}
// catch(Exception $e) catch any exception
catch(ModelNotFoundException $e)
{
    dd(get_class_methods($e)) // lists all available methods for exception object
    dd($e)
}
comments powered by Disqus

Ads cover the costs of maintaining Laravel-tricks