I am trying to find a way to handle exceptions in the way I did in Laravel 4.2, but I can't find the proper way to do it. In Laravel 4.2 I used them for different Error handling, custom 404 page and logging fatal errors or sending emails to the administrator. The case with Laravel5 seems to be different. I've read a lot of topics and most people say they used ErrorServiceProvider that comes with Laravel 5 but Tylor decided to remove it from the project. I see there is a Handler class in the Exception folder but it does not feel as intuitive to put it there as it was with App:error, App::fatal and App::missing in the global.php file in Laravel 4. How do I achieve my goal and keep it simple?
You can either use a Service Provider, or if you feel comfortable with the idea of global.php, just load a file via composer.json and put the App::error, App::fatal and all those right there.
I saw the Kernel class handle method try/catch method but it seems a little bit messy and it looks like you are doing something in a place you should leave as simple as possible. Service provider is a good idea but how exactly do you achieve it with it?
I took the parent Illuminate\Foundation\Exceptions\Handler isHttpException function and copied it to app/Exceptions/Handler.php and changed it's name to my isUserNotFoundException.
protected function isUserNotFoundException(Exception $e)
{
return $e instanceof UserNotFoundException;
}
and than in the render function add
if ($this->isUserNotFoundException($e))
return redirect()->home()->with('notification', $e->getMessage() );
Yes it works like that but am I the only one that thinks this is far more messy than the Laravel 4 approach? Tylor actually spent some time in the past thinking about exceptions, errors and 404 rendering and out of the sudden it's all gone. I know it's still in development but I really hope they are gonna come up with sth simple and nice - the way they do it best.