Thursday, April 13, 2017

Using onDelete cascading

im trying to use in my app on delete cascading, and maybe im not doing right but i had the idea when i delete in my case a product automaticlly would be deleted the columns related with it.

My case:

DB:

products:
- id_product;
- status;

products_translations:
- id;
- product_id;
- name;
- description;
- locale;

My migration that makes the relation and use cascading delete:

 Schema::table('product_translations', function (Blueprint $table) {
            $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
        });

Controller where i make the delete product:

$product = Product::find($id);
        $product->delete();
        return back();



via Pedro

Advertisement