Both solutions should work - if you want to update the pivot table you can do the following:
$pivot = $student->institutionContacts() ->withPivot(['id', 'institution_contact_id', 'student_id', 'type']) ->wherePivot('type',1) ->first()->pivot;
$attributes = ['institution_contact_id' => $newId] // put whatever attributes you want to update (i'm guessing you want to update institution_contact_id
$student->institutionContacts()->newPivotStatementForId($pivot->id)->update($attributes);
This will also hit the Database twice:
- select on the related Model table joined with the pivot table for the desired condition: (student_id = ? and type=1 limit1)
- update the pivot record attributes for the requested pivot id
If you want to detach/attach each time you would want to perform an update make sure to roll both operations inside a transaction.