added pointer interfaces for jobs

This commit is contained in:
Denis Duliçi
2021-09-06 11:53:57 +03:00
parent abd55133f1
commit c08a8cfc4e
63 changed files with 635 additions and 1524 deletions

View File

@ -3,34 +3,18 @@
namespace App\Jobs\Auth;
use App\Abstracts\Job;
use App\Interfaces\Job\ShouldDelete;
class DeleteUser extends Job
class DeleteUser extends Job implements ShouldDelete
{
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()
public function handle(): bool
{
$this->authorize();
\DB::transaction(function () {
$this->user->delete();
$this->model->delete();
$this->user->flushCache();
$this->model->flushCache();
});
return true;
@ -38,13 +22,11 @@ class DeleteUser extends Job
/**
* Determine if this action is applicable.
*
* @return void
*/
public function authorize()
public function authorize(): void
{
// Can't delete yourself
if ($this->user->id == user()->id) {
if ($this->model->id == user()->id) {
$message = trans('auth.error.self_delete');
throw new \Exception($message);