How to Make a Foreign Key Column Nullable in Laravel
In this lesson, we will see how to make a foreign key column nullable in Laravel, sometimes when creating a Laravel migration you want a foreign key to be null, so let's see how we can do that.
Set foreign key default value to null
So to set the foreign key default value to null use the code below:
$table->foreignId('subcategory_id')->nullable()->constrained()->onDelete('cascade');