how to use model not found exception handler laravel

127

App::error(function(Illuminate\Database\Eloquent\ModelNotFoundException $exception) {

    // Log the error
    Log::error($exception);

    // Redirect to error route with any message
    return Redirect::to('error')->with('message', $exception->getMessage());
});
try {
    $menus = Menu::where('parent_id', '>', 100)->firstOrFail();
}catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
    $message = 'Invalid parent_id.';
    return Redirect::to('error')->with('message', $message);
}
App::error(function(Exception $exception, $code) {
    Log::error($exception);
});

Comments

Submit
0 Comments