forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateUserRole.php
More file actions
66 lines (56 loc) · 1.46 KB
/
UpdateUserRole.php
File metadata and controls
66 lines (56 loc) · 1.46 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
59
60
61
62
63
64
65
66
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
use function Laravel\Prompts\confirm;
use function Laravel\Prompts\info;
use function Laravel\Prompts\select;
use function Laravel\Prompts\text;
class UpdateUserRole extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:update-user-role';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Change the role for a given user.';
/**
* Execute the console command.
*/
public function handle()
{
$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'
);
$confirmed = confirm(
label: 'Are you sure?',
required: true
);
if ($confirmed) {
User::firstWhere('email', $email)
->update([
'role' => $role,
]);
info('User role updated.');
}
}
}