laravel many to many belongs to 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: many to many relationship laravel
use App\Models\User;
$user = User::find(1);
$user->roles()->attach($roleId);