mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 15:16:53 +01:00 
			
		
		
		
	 3ec90264bd
			
		
	
	
		3ec90264bd
		
			
		
	
	
	
	
		
			
			* remove `guard_name` from api and add id to transformer * disallow update/ delete for root admin role via api * disallow assigning root admin via api * add api to remove user roles * fix assignRoles & removeRoles
		
			
				
	
	
		
			48 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Transformers\Api\Application;
 | |
| 
 | |
| use App\Models\Role;
 | |
| use League\Fractal\Resource\Collection;
 | |
| use League\Fractal\Resource\NullResource;
 | |
| 
 | |
| class RoleTransformer extends BaseTransformer
 | |
| {
 | |
|     protected array $availableIncludes = [
 | |
|         'permissions',
 | |
|     ];
 | |
| 
 | |
|     /**
 | |
|      * Return the resource name for the JSONAPI output.
 | |
|      */
 | |
|     public function getResourceName(): string
 | |
|     {
 | |
|         return Role::RESOURCE_NAME;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Transform role into a representation for the application API.
 | |
|      */
 | |
|     public function transform(Role $model): array
 | |
|     {
 | |
|         return [
 | |
|             'id' => $model->id,
 | |
|             'name' => $model->name,
 | |
|             'created_at' => $model->created_at->toAtomString(),
 | |
|             'updated_at' => $model->updated_at->toAtomString(),
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Include the permissions associated with this role.
 | |
|      *
 | |
|      * @throws \App\Exceptions\Transformer\InvalidTransformerLevelException
 | |
|      */
 | |
|     public function includePermissions(Role $model): Collection|NullResource
 | |
|     {
 | |
|         $model->loadMissing('permissions');
 | |
| 
 | |
|         return $this->collection($model->getRelation('permissions'), $this->makeTransformer(RolePermissionTransformer::class), 'permissions');
 | |
|     }
 | |
| }
 |