Laravel CustomException class in Laravel CustomException class in laravel

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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



Got any Laravel Question?