Blame view

app/Transformers/Auth/Role.php 872 Bytes
b7c7a5f6   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  <?php
  
  namespace App\Transformers\Auth;
  
  use App\Models\Auth\Role as Model;
  use League\Fractal\TransformerAbstract;
  
  class Role extends TransformerAbstract
  {
      /**
       * @var array
       */
      protected $defaultIncludes = ['permissions'];
  
      /**
       * @param Model $model
       * @return array
       */
      public function transform(Model $model)
      {
          return [
              'id' => $model->id,
              'name' => $model->display_name,
              'code' => $model->name,
              'created_at' => $model->created_at->toIso8601String(),
              'updated_at' => $model->updated_at->toIso8601String(),
          ];
      }
  
      /**
       * @param Model $model
       * @return \League\Fractal\Resource\Collection
       */
      public function includePermissions(Model $model)
      {
          return $this->collection($model->permissions, new Permission());
      }
  }