If you have summary variables:
Relations, if you have summary variables:
public function workers()
{
return $this->belongsToMany('App\Worker')->withTimestamps()->withPivot('value', 'value2');
}
$ array:
$workers[$order_id] = [
...
'value' => $value,
'created_at' => $created_at,
'updated_at' => $updated_at,
]
If you do not have send summary variables and an array of order IDs
$order->workers()->where('assignment','Reassigned')->sync([1,2,3]);
Edit:
Try with clausule clause in new feature
public function workersReassigned()
{
return $this->belongsToMany('App\Worker')->where('assignment','Reassigned')->withTimestamps()->withPivot('value', 'value2');
}
And after:
$order->workersReassigned()->sync($workers);
source
share