akaunting/app/Jobs/Auth/CreateRole.php

32 lines
797 B
PHP
Raw Normal View History

2019-11-16 07:21:14 +00:00
<?php
namespace App\Jobs\Auth;
use App\Abstracts\Job;
2022-06-01 07:15:55 +00:00
use App\Events\Auth\RoleCreated;
use App\Events\Auth\RoleCreating;
2021-09-07 07:33:34 +00:00
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
2021-09-06 08:53:57 +00:00
use App\Interfaces\Job\ShouldCreate;
2019-11-16 07:21:14 +00:00
use App\Models\Auth\Role;
2021-09-07 07:33:34 +00:00
class CreateRole extends Job implements HasOwner, HasSource, ShouldCreate
2019-11-16 07:21:14 +00:00
{
2021-09-06 08:53:57 +00:00
public function handle(): Role
2019-11-16 07:21:14 +00:00
{
2022-06-01 07:15:55 +00:00
event(new RoleCreating($this->request));
2020-06-26 10:40:19 +00:00
\DB::transaction(function () {
2021-09-06 08:53:57 +00:00
$this->model = Role::create($this->request->input());
2019-11-16 07:21:14 +00:00
2020-06-26 10:40:19 +00:00
if ($this->request->has('permissions')) {
2021-09-06 08:53:57 +00:00
$this->model->permissions()->attach($this->request->get('permissions'));
2020-06-26 10:40:19 +00:00
}
});
2019-11-16 07:21:14 +00:00
2022-06-01 07:15:55 +00:00
event(new RoleCreated($this->model, $this->request));
2021-09-06 08:53:57 +00:00
return $this->model;
2019-11-16 07:21:14 +00:00
}
}