Just like how services like
Would do. Just one change, those would be added inside laravel project as a package where they would hijack the same from.
So anytime any error occurs, the dev. team will get a mail immediately so that we can manage such incidents.
If we want to know the GET or POST parameters of that request we can add this later in the tool, to mail it for us
- Remember to also update the .env file with your mailgun credentials
- Customize the SendEmails.php as per your needs, do not use or introduce $message variable as Laravel already uses the same variable in it's framework
- If you do not want basic 404 exceptions to be mailed to your developer / ellipsonic email id, please update the protected $dontReport array present in app/Exceptions/Handler.php
- Copy paste the SendEmails.php inside App\Console\Commands - don't forget to add it as a command in it's Kernel.php
- Add ErrorOccurredEvent.php inside App\Events
- Add IssueEventListener.php inside App\Listeners
- Add event and event listener inside the EventServiceProvider.php
- Please make sure you test the app once all these are done, in-order to ensure the existing features are not broken
- Mailgun sandbox account would not send mail if the project is in production *
Let's not forget the base truth, laravel is an excellent framework, build on top of ' symfony ' php framework. Now that being said, every time an error occurs, the \Symfony\Component\HttpKernel\Exception\NotFoundHttpException class handles the exception. Hence the following steps
- We catch the exception using the same \Symfony\Component\HttpKernel\Exception\NotFoundHttpException class
- We trigger the ErrorOccurredEvent which in turn triggers IssueEventListener class
- This IssueEventListener will run the SendEmails console commmand and send the email to the developer about the exception
No need to handle every exception on our code which we create, all default exceptions will be handedle here, this is the parent of the exception handler, which means, less work for us and whenever an exception occurs the mail will have complete details of
- Which class
- Which method
- Until which line number
Just like papertrial. Decorate the email view the way you want it to look like.
Good news Laravel 5.5 will have more handlers in-built which will help us more as we improve this exception handling. Will update this gist / add a new gist once Laravel 5.5 is released.