lara68236's avatar

Saving errors to DB / Custom error messages

Im using Laravel 5.4. In my app I want to log to the database error messages created by specific methods. I also want to display a custom message to the user and refer them back to a specific page once they acknowledge the error.

Are there any tutorials out there to help explain how I might do this? Any thoughts or advice on the direction to go?

Some people in chat suggested some third-party stuff, but that is not an option where I work. It all has to be done internally.

Thanks in advance for your help.

0 likes
3 replies
aurawindsurfing's avatar
Level 50

Hi @cservices

Ok so to break your question in 2 separate ones:

I want to log to the database error messages created by specific methods.

To do this you would have to create a custom driver. As you can see however it is not a very popular solution judging by a number of stars on this package. Why would you not want what everyone else uses to log errors eg. files?

https://github.com/danielme85/laravel-log-to-db https://laravel.com/docs/master/logging#introduction

I also want to display a custom message to the user and refer them back to a specific page once they acknowledge the error.

What you are talking about here is handling exceptions (errors) what normally happens is you get a standard laravel 403 page or something, but you might customise all of it and on the page, you design ask you ser for acknowledgement and redirect back. Here is a nice tutorial on how to handle the exceptions

https://laraveldaily.com/how-to-catch-handle-create-laravel-exceptions/

Hope it helps!

lara68236's avatar

Thanks for the info. You direction led me to more understanding of how logs work in Laravel. I found that I could actually split the logs to daily, and how I can add my own text to them.

Please or to participate in this conversation.