first commit
Some checks failed
Build / run (push) Has been cancelled

This commit is contained in:
maher
2025-10-29 11:42:25 +01:00
commit 703f50a09d
4595 changed files with 385164 additions and 0 deletions

70
common/Auth/Roles/Role.php Executable file
View File

@@ -0,0 +1,70 @@
<?php namespace Common\Auth\Roles;
use App\Models\User;
use Common\Auth\Permissions\Traits\HasPermissionsRelation;
use Common\Core\BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Role extends BaseModel
{
use HasPermissionsRelation;
const MODEL_TYPE = 'role';
protected $guarded = ['id'];
protected $hidden = ['pivot', 'legacy_permissions'];
protected $casts = [
'id' => 'integer',
'default' => 'boolean',
'guests' => 'boolean',
'internal' => 'boolean',
];
/**
* Get default role for assigning to new users.
*/
public function getDefaultRole(): ?Role
{
return $this->where('default', 1)->first();
}
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class, 'user_role')->withPivot(
'created_at',
);
}
public function toNormalizedArray(): array
{
return [
'id' => $this->id,
'name' => $this->name,
'model_type' => self::MODEL_TYPE,
];
}
public function toSearchableArray(): array
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'type' => $this->type,
'created_at' => $this->created_at->timestamp ?? '_null',
'updated_at' => $this->updated_at->timestamp ?? '_null',
];
}
public static function filterableFields(): array
{
return ['id', 'type', 'created_at', 'updated_at'];
}
public static function getModelTypeAttribute(): string
{
return Role::MODEL_TYPE;
}
}