mardi 24 juillet 2018

Laravel / Eloquent - How Do You Add An Additional wherePivot() Condition To An updateExistingPivot() Call?

I have a reference table with the following columns:

-user_id (foreign key)
-location_id (foreign key)
-skill_level
-court_id

I can update the skill_level pivot column value in the above table with:

$user = User::find($user_id)
$user->locations()->updateExistingPivot($location_id, array(
    'skill_level' => $new_value
));

I would like to add something akin to a wherePivot() to the above so that only records that matches a certain court_id (in addition to user_id and location_id) are updated. Something similar to:

->wherePivot('court_id', '=', $court_id);

How would I do this with an updateExistingPivot() call?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire