-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAddToHz.php
66 lines (56 loc) · 1.74 KB
/
AddToHz.php
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\Team;
use App\Models\User;
use Illuminate\Console\Command;
use Exception;
use Laravel\Jetstream\Contracts\AddsTeamMembers;
class AddToHz extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'admin:add-to-hz {email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Adds the person with the given email to the HZ team';
/**
* Execute the console command.
* @throws Exception
*/
public function handle()
{
$userEmail = $this->argument('email');
$user = User::where('email', $userEmail)->first();
if (!$user) {
$this->error('Adding to HZ team failed. User with such email does not exist');
return;
}
$teamHz = Team::where('name', 'HZ University of Applied Sciences')->first();
if (!$teamHz) {
$this->error('Adding to HZ team failed. Team HZ seems to be missing');
return;
}
if ($user->currentTeam) {
$this->error("Seems that {$user->name} (email: {$user->email}) is already a part from a company");
return;
}
try {
app(AddsTeamMembers::class)->add(
$teamHz->owner,
$teamHz,
$user->email,
'speaker'
);
$user->switchTeam($teamHz);
$this->info("You successfully added {$user->name} (email: {$user->email}) to the HZ team");
} catch (Exception) {
$this->error("Seems that there was an issue in adding {$user->name} (email: {$user->email}) to HZ");
}
}
}