add role permission logic
This commit is contained in:
@@ -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),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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)),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user