How do I catch a query exception in laravel to see if it fails?

前端 未结 3 670
甜味超标
甜味超标 2020-12-15 16:28

All I\'m trying to do is verify a query.

\'SELECT * from table_that_does_not_exist\'

Without that erroring out, I\'d like to know it failed

3条回答
  •  眼角桃花
    2020-12-15 17:17

    If you want to catch all types of database exceptions you can catch it on laravel Exception Handler

    if ($exception instanceof \PDOException) {
        # render a custom error
    }
    

    for more details about how to use laravel Exception Handler check https://laravel.com/docs/7.x/errors

提交回复
热议问题