CustomException class in Laravel

Other topics

CustomException class in laravel

all errors and exceptions, both custom and default, are handled by the Handler class in app/Exceptions/Handler.php with the help of two methods.

  • report()

  • render()

    public function render($request, Exception $e)
    {
     //check if exception is an instance of ModelNotFoundException.
     if ($e instanceof ModelNotFoundException)
     {
         // ajax 404 json feedback
         if ($request->ajax())
         {
             return response()->json(['error' => 'Not Found'], 404);
         }
         // normal 404 view page feedback
         return response()->view('errors.missing', [], 404);
      }
       return parent::render($request, $e);
    }
    

then create view related to error in errors folder named 404.blade.php

User not found.

You broke the balance of the internet

Contributors

Topic Id: 9550

Example Ids: 29507

This site is not affiliated with any of the contributors.