Mutator does not work with bulk insert

I am trying to insert multiple entries in laravel using Order::insert($orderArray); I made a mutator which

public function setOrderDetailAttribute($value)
{
    if ($value)
    {
        $this->attributes['order_detail'] = serialize($value);
    }
}

the mutator is not working. But when I record a single recording using Order::create($orderArray[0][0]);Then the mutator is working fine. My question is: how can I use a mutator with insert function or bulk insert.

+4
source share
1 answer

When you call Order::insert($orderArray);, it does not really affect Eloquent. It simply proxies the call to the Query \ Builder @insert () method.

Therefore, I think that the mutator cannot be used in this way.

+1
source

Source: https://habr.com/ru/post/1648209/


All Articles