My question is related to Laravel, I have product model and categories. They have a relationship with category_id as a foreign key to product table, my question is, I need when I delete a category, this category_id related field be NULL, I mean, there's a Laravel way to do it? Without be in migration.
This is my Category Model:
public function products()
{
return $this->hasMany('App\Models\Product');
}
This is my Product model:
public function category()
{
return $this->belongsTo('App\Models\Category')->withDefault(function ($data) {
foreach($data->getFillable() as $dt){
$data[$dt] = __('Deleted');
}
});
}