I am working on a Laravel App, and in a Migration, I want to update certain objects. For this my Migration has the following code:
public function up()
{
//Update the filter whose current name is City
$filter= App\Filter::where('name', 'City')->firstOrFail();
if($filter){
$filter->name='City Region Type';
$filter->description='City Region Type';
$filter->save();
}
}
I also have an Observer on this class which puts in the user_id of the user who is doing the update, using:
public function updating(Filter $filter)
{
$filter->updated_by = auth()->user()->id;
}
Running this migration fails, because it cannot get the user_id.
What's the Recommended way to write a Migration when you have an Obser set up like this?
Or Do I give up and use Raw SQL?