0

When deleting an entity in Laravel-Admin having a relationship, a not-so-informative error dialog box crashes from the user's point of view.

How to handle this exception in the framework of Laravel-Admin in order to give the user an informative error message?

Thank you for your suggestions.

enter image description here

Salim Djerbouh
  • 10,719
  • 6
  • 29
  • 61
devAston
  • 63
  • 10

1 Answers1

1

You should add ->onDelete('cascade') on your foreign key in migration.

Example: $table->foreign('point_sale_online_id')->references('id')->on('point_sale_online')->onDelete('cascade');

But I guess that you want to achieve that user has to validate deleting something. The way I do this: delete button fires modal with confirm button, which is a submit to the form with SomethingController@destroy action. Nevertheless to achieve that you need to add this onDelete method. Then you can simply do

if(App\Something::find($id)->delete(){
//all good code
} else {
// something went wrong code
}

Norbert Jurga
  • 204
  • 4
  • 14