104 lines
2.6 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
namespace App\Models\Auth;
2022-06-01 10:15:55 +03:00
use Akaunting\Sortable\Traits\Sortable;
2020-05-02 14:53:06 +03:00
use App\Traits\Tenants;
2022-07-07 17:35:24 +03:00
use Bkwld\Cloner\Cloneable;
2019-11-16 10:21:14 +03:00
use Laratrust\Models\LaratrustRole;
2017-09-14 22:21:00 +03:00
use Laratrust\Traits\LaratrustRoleTrait;
2019-11-16 10:21:14 +03:00
use Lorisleiva\LaravelSearchString\Concerns\SearchString;
2017-09-14 22:21:00 +03:00
class Role extends LaratrustRole
{
2022-07-07 17:35:24 +03:00
use Cloneable, LaratrustRoleTrait, SearchString, Sortable, Tenants;
2019-11-16 10:21:14 +03:00
2017-09-14 22:21:00 +03:00
protected $table = 'roles';
/**
* The attributes that are mass assignable.
*
* @var array
*/
2021-09-07 10:33:34 +03:00
protected $fillable = ['name', 'display_name', 'description', 'created_from', 'created_by'];
2017-09-14 22:21:00 +03:00
2022-07-07 17:35:24 +03:00
/**
* Clonable relationships.
*
* @var array
*/
public $cloneable_relations = ['permissions'];
2022-06-01 10:15:55 +03:00
/**
* Get the line actions.
*
* @return array
*/
public function getLineActionsAttribute()
{
$actions = [];
$actions[] = [
'title' => trans('general.edit'),
'icon' => 'edit',
'url' => route('roles.roles.edit', $this->id),
'permission' => 'update-roles-roles',
2022-09-06 13:54:56 +03:00
'attributes' => [
'id' => 'index-line-actions-edit-role-' . $this->id,
],
2022-06-01 10:15:55 +03:00
];
$actions[] = [
'title' => trans('general.duplicate'),
'icon' => 'file_copy',
'url' => route('roles.roles.duplicate', $this->id),
'permission' => 'create-roles-roles',
2022-09-06 13:54:56 +03:00
'attributes' => [
'id' => 'index-line-actions-duplicate-role-' . $this->id,
],
2022-06-01 10:15:55 +03:00
];
$actions[] = [
'type' => 'delete',
'icon' => 'delete',
'route' => 'roles.roles.destroy',
'permission' => 'delete-roles-roles',
2022-09-06 13:54:56 +03:00
'attributes' => [
'id' => 'index-line-actions-delete-role-' . $this->id,
],
2022-06-01 10:15:55 +03:00
'model' => $this,
];
return $actions;
}
2017-09-14 22:21:00 +03:00
/**
* Scope to get all rows filtered, sorted and paginated.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param $sort
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCollect($query, $sort = 'display_name')
{
$request = request();
2019-11-16 10:21:14 +03:00
$search = $request->get('search');
$limit = (int) $request->get('limit', setting('default.list_limit', '25'));
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
return $query->usingSearchString($search)->sortable($sort)->paginate($limit);
2017-09-14 22:21:00 +03:00
}
2022-07-07 17:45:09 +03:00
/**
* @inheritDoc
*
* @param Document $src
* @param boolean $child
*/
public function onCloning($src, $child = null)
{
$this->name = $src->name . '-' . Role::max('id') + 1;
}
2017-09-14 22:21:00 +03:00
}