laravel 8 many to many relationship 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: laravel many to many migration
php artisan make:migration create_posts_users_table
Example 3: many to many relationship laravel
use App\Models\User;
$user = User::find(1);
$user->roles()->attach($roleId);