Inserting & Updating Related Models (Many To Many Relationships)
https://viblo.asia/p/eloquent-relationships-in-laravel-phan-3-MJykjmxyePB
$user = App\User::find(1);
$user->roles()->attach($roleId);$user->roles()->attach($roleId, ['expires' => $expires]);// Detach a single role from the user...
$user->roles()->detach($roleId);
// Detach all roles from the user...
$user->roles()->detach();$user = App\User::find(1);
$user->roles()->detach([1, 2, 3]);
$user->roles()->attach([1 => ['expires' => $expires], 2, 3]);PreviousInserting & Updating Related Models (Belongs To Relationships)NextInserting & Updating Related Models (Syncing Associations)
Last updated