how set cascade on delete and update in same time in laravel
$table->foreign('user_id')->references('id')->on('users') ->onDelete('SET NULL') ->onUpdate('SET NULL'); // also available CASCADE, RESTRICT, DO NOTHING, NO ACTION
Here is what the above code is Doing:
1. We’re adding a new column to the posts table called user_id.
2. We’re telling Laravel that this column is an unsigned integer.
3. We’re telling Laravel that this column is a foreign key that references the id column on the users table.
4. We’re telling Laravel that if a user is deleted, we want to set the user_id column to NULL.
5. We’re telling Laravel that if a user is updated, we want to set the user_id column to NULL.