Answers for "laravel find or fail exception"

PHP
0

laravel find or fail exception

use Illuminate\Database\Eloquent\ModelNotFoundException;

// 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);
}
Posted by: Guest on August-15-2020

Browse Popular Code Answers by Language