Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show 500 internal Server error page in laravel 5.2?

I want to show the page 500 internal server error Page. when user had syntax error mistake in project can anyone help me? if i do some mistake in syntax i want to show that particular blade.

like image 279
kunal Avatar asked Dec 19 '16 06:12

kunal


People also ask

Where can I find 500 internal server error?

Delete your browser's cookies. You can correct some 500 Internal Server Error issues by deleting the cookies associated with the site on which you're getting the error. After removing the cookie(s), restart the browser and try again. Troubleshoot as a 504 Gateway Timeout error instead.

How can I print 500 error in php?

Quickly Show All PHP Errors The quickest way to display all php errors and warnings is to add these lines to your PHP code file: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

How do I enable error reporting in laravel?

Through your config/app. php , set 'debug' => env('APP_DEBUG', false), to true . Or in a better way, check out your . env file and make sure to set the debug element to true.


2 Answers

You need to create handler to catching FatalErrorExceptions in your handler like below code:

Handler In app/Exceptions/Handler.php

public function render($request, Exception $e)
{

    // 404 page when a model is not found
    if ($e instanceof ModelNotFoundException) {
        return response()->view('errors.404', [], 404);
    }

    // custom error message
    if ($e instanceof \ErrorException) {
        return response()->view('errors.500', [], 500);
    } else {
        return parent::render($request, $e);
    }

    return parent::render($request, $e);
}

View See resources/views/errors/500.blade.php. If not exist then create it.

You can get more detailed OR other ways from Laravel 5 custom error view for 500

like image 112
AddWeb Solution Pvt Ltd Avatar answered Oct 05 '22 23:10

AddWeb Solution Pvt Ltd


In your resources/views/errors folder create a file named 500.blade.php.

Laravel makes it easy to display custom error pages for various HTTP status codes. For example, if you wish to customize the error page for 500 HTTP status codes, create a resources/views/errors/500.blade.php. This file will be served on all 500 errors generated by your application.

The problem is that Laravel will only do this automatic rendering of error pages for exceptions that are instances of HttpException. Unfortunately when your server throws an error (method does not exist, variable undefined, etc) it actually throws a FatalErrorException. As such, it is uncaught, and trickles down to the SymfonyDisplayer() which either gives you the trace (debug true) or ugly one-liner 'Whoops, looks like something went wrong' (debug false).

To solve this you have add this to your render method to app/Exceptions/Handler

# /app/Exceptions/Handler.php

# use Symfony\Component\Debug\Exception\FlattenException;

# public function render($request, Exception $e)

$exception = FlattenException::create($e);
$statusCode = $exception->getStatusCode($exception);

if ($statusCode === 404 or $statusCode === 500) {
    return response()->view('errors.' . $statusCode, [], $statusCode);
}

Docs

like image 24
Amit Gupta Avatar answered Oct 05 '22 22:10

Amit Gupta