-1

Let's say Here . I have an extra column on intermediate table 'noOfUpdates' then how can i access its previous value.

I tried this but it didn't work.

$user = User::find(1);

$user->roles()->updateExistingPivot($roleId, [
    'noOfUpdates' => noOfUpdates + 1,
]);

In raw SQL i can to do that. n_enroll column

sorry for my english :(

PLEASE HELP

Stark
  • 3
  • 2

1 Answers1

1

you can use newPivotQuery along with increment, newPivotQuery creates a new query builder for the pivot table.

$user->roles()->newPivotQuery()->where('user_id',$user->id)
->where('role_id',$roleId)->increment('noOfUpdates');
OMR
  • 11,736
  • 5
  • 20
  • 35
  • thanks . but, i just wondering if there is a simple method exit like updateExistingPivot(). I don't wanna chain multiple constraints. also what if I want to do something like [noOfUpdates + 3]. but thanks – Stark Nov 18 '21 at 13:52
  • if you want to do something like noOfUpdated +3 you can use ->increment('noOfUpdates',3) – OMR Nov 18 '21 at 13:54
  • wow. I should have read the query builer docs completly. thanks again : ) – Stark Nov 18 '21 at 14:08