As mentioned in here, we can use the word cascade
when making a relation in migrations
but I wonder they didn't say anything about other actions when deleting
or updating
a foreign key
so I'm not sure if there is such thing or not:
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('set null');
//->onDelete('set_null');
//->onDelete('setNull');
or the same thing about onUpdate
and about no action
just like the phpMyAdmin
thanks
You can do all the options mentioned in phpmyadmin
this way:
$table->...->onDelete('CASCADE');
$table->...->onDelete('SET NULL');
$table->...->onDelete('RESTRICT');
// do not call the onDelete() method if you want the RESTRICT option.
You have to make sure you set the foreign key field as nullable:
$table->...->unsigned()->nullable();