2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\Auth;
|
|
|
|
|
|
|
|
use App\Abstracts\Job;
|
|
|
|
use App\Models\Auth\Role;
|
|
|
|
|
|
|
|
class CreateRole extends Job
|
|
|
|
{
|
2020-06-26 13:40:19 +03:00
|
|
|
protected $role;
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
protected $request;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @param $request
|
|
|
|
*/
|
|
|
|
public function __construct($request)
|
|
|
|
{
|
|
|
|
$this->request = $this->getRequestInstance($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return Permission
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2020-06-26 13:40:19 +03:00
|
|
|
\DB::transaction(function () {
|
|
|
|
$this->role = Role::create($this->request->input());
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
if ($this->request->has('permissions')) {
|
|
|
|
$this->role->permissions()->attach($this->request->get('permissions'));
|
|
|
|
}
|
|
|
|
});
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
return $this->role;
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
}
|