I'm building a Laravel app and everything is working fine (as far as I can see) and now I would like to make the website public.
However I can't figure out how to implement custom messages for bad/unauthorized request.
I know I can put views in /resources/views/errors/ folder like:
404.blade.php
503.blade.php
... and so on.
However I'm not sure for which errors should I build views or is there a simpler way to make one main view for all errors. There is no reason to notify user which error occurred but if it can be done easily I would go that way.
Here is the list of all errors that I just Googled: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
Here is the Laravel 5.1 error documentation: http://laravel.com/docs/5.1/errors
I tried changing the file /app/Exceptions/Handler.php and in it function
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
return parent::render($request, $e);
}
to
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
return view('errors.allerrors'); // only this line is changed
}
but that only returns empty page.
Thanks.
I will leave this as a partial answer in case someone ends up here with the same problem.
The answer will not redirect all errors to the same page but will handle most of the errors, as far as I can tell.
Add these files to the /resources/views/errors/
folder:
401.blade.php - this page will be shown if user is not authorized to access the webpage (when you are using some kind of user authentification)
404.blade.php - this page will be shown if user writes url that you haven't declared in your /app/Http/routes.php file
503.blade.php - this page will be shown when your site is down, ie. when you run the php artisan down
command
There is still one error page that I don't know how to hadle, better say, I don't know its error number. It shows when an user tries to access the model instance (I don't know the right terminology here so please correct me) that doesn't exist. In example; if an user tries to acces yourwebsite.com/articles/123
but you don't have article with that id/slug in your db you will still get an whoops...
message.
I am not completely satisfied with this solution, since there might be other errors I wasn't able to produce, but it's best/only solution I have.