Laravel check for constraint violation

后端 未结 5 2106
野的像风
野的像风 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 12:18

    You may also try

    try {
           ...
        } catch ( \Exception $e) {
             var_dump($e->errorInfo );
        }
    

    then look for error code.

    This catches all exception including QueryException

提交回复
热议问题