76 lines
1.9 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;
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-06-01 10:15:55 +03:00
use 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-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',
];
$actions[] = [
'title' => trans('general.duplicate'),
'icon' => 'file_copy',
'url' => route('roles.roles.duplicate', $this->id),
'permission' => 'create-roles-roles',
];
$actions[] = [
'type' => 'delete',
'icon' => 'delete',
'route' => 'roles.roles.destroy',
'permission' => 'delete-roles-roles',
'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
}
}