When i get this error:
QueryException in Connection.php line 620: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
can i handle it with my own flash error message instead of:
Whoops, looks like something went wrong
When i get this error:
QueryException in Connection.php line 620: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
can i handle it with my own flash error message instead of:
Whoops, looks like something went wrong
You have two ways to handle exceptions and show a custom response:
1) Let the framework handle them for you:
If you don't handle exceptions by yourself, Laravel will handle them in the class:
In the
render
method you can intercept the renderning of all the exceptions the framework rises. So, if you want to do something in particular when a specific exception rises, you can modify that method this way:2) Handle the exceptions by yourself:
You can handle exceptions by yourself, with
try-catch
blocks. For example in a controller's method:The main difference between the two cases is that in case 1 you are defining a general, application-wide approach to handle specific exceptions.
On the other hand, in case 2, you can define exception hadling in specific points of your application
This is work with me fine