0

When I tried to delete a row which ID related to another table I got this error

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row

How can I show this error. I've tried with try catch (\Illuminate\Database\QueryException $e) But it not work Can I have your help!

1 Answer 1

1

Please try with PDO exception

    try {
            $this->model->create($data);

        } catch (Illuminate\Database\QueryException $e) {
            dd($e);

        } catch (PDOException $e) {
            dd($e);
        }  
Sign up to request clarification or add additional context in comments.

2 Comments

I use your code with try { $brand->delete() }..... But I still got it error. I think I wrong somewhere so It can not catch.
@SangTrần di you try both query and pdo exception?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.