2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\Auth;
|
|
|
|
|
|
|
|
use App\Abstracts\Job;
|
2022-06-01 10:15:55 +03:00
|
|
|
use App\Events\Auth\RoleUpdated;
|
|
|
|
use App\Events\Auth\RoleUpdating;
|
2021-09-06 11:53:57 +03:00
|
|
|
use App\Interfaces\Job\ShouldUpdate;
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Models\Auth\Role;
|
|
|
|
|
2021-09-06 11:53:57 +03:00
|
|
|
class UpdateRole extends Job implements ShouldUpdate
|
2019-11-16 10:21:14 +03:00
|
|
|
{
|
2021-09-06 11:53:57 +03:00
|
|
|
public function handle(): Role
|
2019-11-16 10:21:14 +03:00
|
|
|
{
|
2022-06-01 10:15:55 +03:00
|
|
|
event(new RoleUpdating($this->model, $this->request));
|
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
\DB::transaction(function () {
|
2021-09-06 11:53:57 +03:00
|
|
|
$this->model->update($this->request->all());
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
if ($this->request->has('permissions')) {
|
2021-09-06 11:53:57 +03:00
|
|
|
$this->model->permissions()->sync($this->request->get('permissions'));
|
2020-06-26 13:40:19 +03:00
|
|
|
}
|
2022-07-20 10:23:51 +03:00
|
|
|
|
|
|
|
$this->model->flushCache();
|
2020-06-26 13:40:19 +03:00
|
|
|
});
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2022-06-01 10:15:55 +03:00
|
|
|
event(new RoleUpdated($this->model, $this->request));
|
|
|
|
|
2021-09-06 11:53:57 +03:00
|
|
|
return $this->model;
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
}
|