Created
June 3, 2018 04:13
-
-
Save rajitha-bandara/ce5f0f58547f9968b5d8f086b010f36b to your computer and use it in GitHub Desktop.
Laravel eloquent delete with handling integrity constraint violation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
$category->delete(); | |
} | |
catch (\Illuminate\Database\QueryException $e) { | |
if($e->getCode() == "23000"){ //23000 is sql code for integrity constraint violation | |
// return error to user here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment