2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\Auth;
|
|
|
|
|
|
|
|
use App\Abstracts\Job;
|
|
|
|
|
|
|
|
class DeleteUser extends Job
|
|
|
|
{
|
|
|
|
protected $user;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @param $user
|
|
|
|
*/
|
|
|
|
public function __construct($user)
|
|
|
|
{
|
|
|
|
$this->user = $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
2020-03-28 22:50:06 +03:00
|
|
|
* @return boolean|Exception
|
2019-11-16 10:21:14 +03:00
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$this->authorize();
|
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
\DB::transaction(function () {
|
|
|
|
$this->user->delete();
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
$this->user->flushCache();
|
|
|
|
});
|
2019-11-16 10:21:14 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if this action is applicable.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
// Can't delete yourself
|
|
|
|
if ($this->user->id == user()->id) {
|
|
|
|
$message = trans('auth.error.self_delete');
|
|
|
|
|
|
|
|
throw new \Exception($message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|