sync or updateExistingPivot with Laravel -- How to fill based on a 3rd critria

If you want to update existing pivot, you can do this:

$model; // parent of the relation
$related; // related object already synced with the $model

$model->relation()->sync([$related->id => [ 'duration' => 'someValue'] ], false);

1st param is array with related model id as key, and array of pivot values to update, while 2nd param set to false means, that you don't detach all the other related models.