add role permission logic

This commit is contained in:
root
2026-03-10 17:11:48 -04:00
parent abebe0d9c0
commit c235fd2170
40 changed files with 1896 additions and 838 deletions
@@ -0,0 +1,19 @@
<?php
namespace App\Http\Resources\Roles;
use Illuminate\Http\Resources\Json\JsonResource;
class PermissionResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this->id ?? $this['id'] ?? 0),
'name' => (string) ($this->name ?? $this['name'] ?? ''),
'description' => $this->description ?? $this['description'] ?? null,
'created_at' => $this->created_at ?? $this['created_at'] ?? null,
'updated_at' => $this->updated_at ?? $this['updated_at'] ?? null,
];
}
}
@@ -0,0 +1,22 @@
<?php
namespace App\Http\Resources\Roles;
use Illuminate\Http\Resources\Json\JsonResource;
class RolePermissionResource extends JsonResource
{
public function toArray($request): array
{
return [
'permission_id' => (int) ($this['id'] ?? $this['permission_id'] ?? 0),
'name' => (string) ($this['name'] ?? ''),
'description' => $this['description'] ?? null,
'can_create' => (int) ($this['can_create'] ?? 0),
'can_read' => (int) ($this['can_read'] ?? 0),
'can_update' => (int) ($this['can_update'] ?? 0),
'can_delete' => (int) ($this['can_delete'] ?? 0),
'can_manage' => (int) ($this['can_manage'] ?? 0),
];
}
}
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace App\Http\Resources\Roles;
use Illuminate\Http\Resources\Json\JsonResource;
class RoleResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this->id ?? $this['id'] ?? 0),
'name' => (string) ($this->name ?? $this['name'] ?? ''),
'slug' => (string) ($this->slug ?? $this['slug'] ?? ''),
'description' => $this->description ?? $this['description'] ?? null,
'dashboard_route' => (string) ($this->dashboard_route ?? $this['dashboard_route'] ?? ''),
'priority' => (int) ($this->priority ?? $this['priority'] ?? 0),
'is_active' => (int) ($this->is_active ?? $this['is_active'] ?? 0),
'user_count' => $this->user_count ?? $this['user_count'] ?? null,
'created_at' => $this->created_at ?? $this['created_at'] ?? null,
'updated_at' => $this->updated_at ?? $this['updated_at'] ?? null,
];
}
}
@@ -0,0 +1,25 @@
<?php
namespace App\Http\Resources\Roles;
use Illuminate\Http\Resources\Json\JsonResource;
class UserWithRolesResource extends JsonResource
{
public function toArray($request): array
{
$roles = $this['roles'] ?? [];
if (is_string($roles)) {
$roles = array_filter(array_map('trim', explode(',', $roles)));
}
return [
'id' => (int) ($this['id'] ?? 0),
'firstname' => (string) ($this['firstname'] ?? ''),
'lastname' => (string) ($this['lastname'] ?? ''),
'email' => (string) ($this['email'] ?? ''),
'account_id' => (string) ($this['account_id'] ?? ''),
'roles' => array_values(array_filter($roles)),
];
}
}