-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
DeleteUser.php
43 lines (32 loc) · 914 Bytes
/
DeleteUser.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
<?php
namespace App\Jobs\Auth;
use App\Abstracts\Job;
use App\Events\Auth\UserDeleted;
use App\Events\Auth\UserDeleting;
use App\Interfaces\Job\ShouldDelete;
class DeleteUser extends Job implements ShouldDelete
{
public function handle(): bool
{
$this->authorize();
event(new UserDeleting($this->model));
\DB::transaction(function () {
$this->deleteRelationships($this->model, ['invitation']);
$this->model->delete();
$this->model->flushCache();
});
event(new UserDeleted($this->model));
return true;
}
/**
* Determine if this action is applicable.
*/
public function authorize(): void
{
// Can't delete yourself
if ($this->model->id == user()->id) {
$message = trans('auth.error.self_delete');
throw new \Exception($message);
}
}
}