/
evo
/
docviz
Обзор
Документация
Войти
/
evo
/
docviz
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
app/Console/Commands/ChangeUserRole.php
56 строк
1 KB
evo
Initial commit
04 фев 2026, 17:00
04 фев 2026, 17:00
6132ae5
Код
Авторство
О чём код?
<?php namespace App\Console\Commands; use Illuminate\Console\Command; use App\Models\User; class ChangeUserRole extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'user:role {email} {role}'; /** * The console command description. * * @var string */ protected $description = 'Change user role'; /** * Execute the console command. */ public function handle() { $email = $this->argument('email'); $role = $this->argument('role'); if (!in_array($role, ['user', 'editor', 'moderator', 'admin', 'owner'])) { $this->error("Invalid role. Must be one of: user, editor, moderator, admin, owner"); return 1; } $user = User::where('email', $email)->first(); if (!$user) { $this->error("User with email '{$email}' not found."); return 1; } $oldRole = $user->role; $user->role = $role; $user->save(); $this->info("User role changed from '{$oldRole}' to '{$role}'"); $this->table( ['ID', 'Name', 'Email', 'New Role'], [[$user->id, $user->name, $user->email, $user->role]] ); return 0; } }