Laravel check for constraint violation

后端 未结 5 2057
野的像风
野的像风 2021-02-05 11:15

I was curious if there is a way we can check if there is a constraint violation error when delete or insert a record into the database.

The exception thrown is called \'

5条回答
  •  后悔当初
    2021-02-05 11:55

    You can add the following code in app/start/global.php file in order to print the exception

    App::error(function(QueryException $exception)
    {
      print_r($exception->getMessage()); 
     });
    

    check this part in the documentation

提交回复
热议问题