forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserChangeRole.php
More file actions
58 lines (49 loc) · 1.27 KB
/
UserChangeRole.php
File metadata and controls
58 lines (49 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
use function Laravel\Prompts\info;
use function Laravel\Prompts\select;
use function Laravel\Prompts\text;
class UserChangeRole extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:user-change-role';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Change the role for a user.';
/**
* Execute the console command.
*/
public function handle(): void
{
$email = text(
label: 'What is the email address?',
required: true,
validate: fn (string $value) => match (true) {
! User::firstWhere('email', $value) => 'User not found.',
default => null
}
);
$role = select(
label: 'What role should the user have?',
options: [
'admin' => 'Admin',
'user' => 'User',
],
default: 'user'
);
User::where('email', '=', $email)
->update([
'role' => $role,
]);
info('User role updated.');
}
}