spatie assign role code example
Example 1: create role spatie
// Create a role or permission if necessary
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
$role = Role::create(['name' => 'writer']);
$permission = Permission::create(['name' => 'edit articles']);
Example 2: update role spatie
// All current roles will be removed from the user and replaced by the array given
$user->syncRoles(['writer', 'admin']);