mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/unity.git
synced 2026-08-19 12:24:01 +00:00
53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Http\Helpers\Hasher;
|
|
use Carbon\Carbon;
|
|
|
|
use Spatie\Permission\Models\Role as SpatieRole;
|
|
use Spatie\Permission\Models\Permission;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Role extends Model
|
|
{
|
|
protected $table = 'roles';
|
|
|
|
protected $appends = ['hash_id', 'permission_list'];
|
|
|
|
protected $hidden = [
|
|
'id',
|
|
'pivot'
|
|
];
|
|
|
|
public function getAllPermissions()
|
|
{
|
|
return SpatieRole::find($this->id)->permissions;
|
|
}
|
|
|
|
public function getHashIdAttribute()
|
|
{
|
|
return Hasher::encode('roles', $this->id);
|
|
}
|
|
|
|
public function getPermissionListAttribute()
|
|
{
|
|
$permission_list = $this->getAllPermissions();
|
|
foreach ($permission_list as $key => $row) {
|
|
$row->hash_id = Hasher::encode('permissions', $row->id);
|
|
}
|
|
return $permission_list;
|
|
}
|
|
|
|
public function getUpdatedAtAttribute($date)
|
|
{
|
|
return $date ? Carbon::parse($date)->timezone('Asia/Kuala_Lumpur')->format('Y-m-d') : '';
|
|
}
|
|
|
|
public function getCreatedAtAttribute($date)
|
|
{
|
|
return $date ? Carbon::parse($date)->timezone('Asia/Kuala_Lumpur')->format('Y-m-d') : '';
|
|
}
|
|
}
|