Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel find or fail exception

use IlluminateDatabaseEloquentModelNotFoundException;

// 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);
}
 
PREVIOUS NEXT
Tagged: #laravel #find #fail #exception
ADD COMMENT
Topic
Name
8+7 =