akaunting/app/Jobs/Auth/DeleteUser.php
2020-06-26 13:40:19 +03:00

54 lines
893 B
PHP

<?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.
*
* @return boolean|Exception
*/
public function handle()
{
$this->authorize();
\DB::transaction(function () {
$this->user->delete();
$this->user->flushCache();
});
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);
}
}
}