Tuesday, February 28, 2017

Catch query exception in laravel

Tags



People that write naked php code are mostly catch the exception of their query using the direct method of mysqli or pdo. This will require more code to be written and more energy to write it.
But in laravel, you can use the provided class to catch it and you don't even have to worry about wrong implementations of query exception. It easy as you only need to follow the steps provided below.

First, include this in your controller.



I will be using some simple query to demonstrate how to use the query exception in laravel.

Controller.php file


web.php (route file)



Run the localhost/test and try to make the query false. You should jump to the "Query Failed" string if it false.

For more info, visit laravel api website for better reference. QueryException

If you are facing any problem on this, don't hesitate to message at Obstrum facebook page.

Hope this tutorial will help those in need.

If you want to get in touch with more tutorial, add me on google+ or like and follow our facebook page for more! Obstrum Facebook Page


EmoticonEmoticon