$user->assignRole('writer');
// You can also assign multiple roles at once
$user->assignRole('writer', 'admin');
// or as an array
$user->assignRole(['writer', 'admin']);
// Create a role or permission if necessary
use SpatiePermissionModelsRole;
use SpatiePermissionModelsPermission;
$role = Role::create(['name' => 'writer']);
$permission = Permission::create(['name' => 'edit articles']);
$role->givePermissionTo($permission);
$permission->assignRole($role);
$role->syncPermissions($permissions);
$permission->syncRoles($roles);