skip to Main Content

I have a website built with laravel 11 and it is live, I want to hide the server errors such as { "status": "exception", "message": "No query results for model [App\Models\Application].", "line": 637, "file": "path_to/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php" }

I edited .env file with APP_DEBUG=false and APP_ENV=production but I got this errors also, I tried to add a blade named 500.blade.php under errors folder with custom message but nothing was changed

But for 404 error I succeed to have a custom page : I created a 404 blade file and I added a route :

 Route::fallback(function () {
        return view('errors.404');
    });

can someone helps to hide the server errors please!

2

Answers


  1. Check the .env file there APP_DEBUG variable:

    Replace that with true to false: APP_DEBUG=false

    After that run this command on terminal: php artisan config:clear

    Login or Signup to reply.
  2. You can try to override the default error handler behavior.
    Take a look at the file bootstrapapp.php. You can try something like this:

    ->withExceptions(function (Throwable|Exceptions $exceptions) {
      
      $exceptions->renderable(function (Throwable|Exceptions $e, $request) {
    
        return response()->view('your_default_error_view_here');
    
      });
    
    })->create();
    

    The code above will render a view for every request (Sure you can improve this code as you want)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search