Blame view

app/Http/Resource.php 720 Bytes
e77200db5   nologostudio.ru   Initial 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
  <?php
  
  namespace FootyRoom\Http;
  
  use Illuminate\Http\Request;
  use Illuminate\Http\Resources\Json\JsonResource;
  
  class Resource extends JsonResource
  {
      /**
       * Resolve the resource to an array.
       *
       * @param \Illuminate\Http\Request|null $request
       *
       * @return array
       */
      public function resolve($request = null)
      {
          if ($this->resource === null) {
              return $this->nullResource();
          }
  
          return parent::resolve($request);
      }
  
      /**
       * Method that gets called instead of toArray() when resource is null.
       *
       * @return array
       */
      public function nullResource(): array
      {
          return [
              'data' => null,
          ];
      }
  }