laravel many to many relation code example
Example: many to many relationship laravel
use App\Models\User;
$user = User::find(1);
$user->roles()->attach($roleId);
use App\Models\User;
$user = User::find(1);
$user->roles()->attach($roleId);