laravel sync relation code example
Example 1: laravel detach
// Detach a single role from the user...
$user->roles()->detach($roleId);
// Detach all roles from the user...
$user->roles()->detach();
Example 2: latavel attach method
$user->roles()->attach($roleId, ['expires' => $expires]);