laravel many to many relationship tutorial 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);