Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rajitha-bandara/ce5f0f58547f9968b5d8f086b010f36b to your computer and use it in GitHub Desktop.
Save rajitha-bandara/ce5f0f58547f9968b5d8f086b010f36b to your computer and use it in GitHub Desktop.
Laravel eloquent delete with handling integrity constraint violation
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