1 | <?php |
||
12 | abstract class TransformerAbstract extends BaseTransformerAbstract |
||
13 | { |
||
14 | const REQUIRED_FIELDS = [ |
||
15 | 'id', |
||
16 | ]; |
||
17 | |||
18 | public function transform($data) |
||
19 | { |
||
20 | $user = auth(config('sarala.guard'))->user(); |
||
|
|||
21 | |||
22 | $links = $this->links($data, $user)->all(); |
||
23 | $meta = $this->meta($data, $user); |
||
24 | $data = $this->filterFields($this->data($data)); |
||
25 | |||
26 | if (! empty($links)) { |
||
27 | $data['links'] = $links; |
||
28 | } |
||
29 | |||
30 | if (! empty($meta)) { |
||
31 | $data['meta'] = $meta; |
||
32 | } |
||
33 | |||
34 | return $data; |
||
35 | } |
||
36 | |||
37 | protected function links($model, $user = null): Links |
||
41 | |||
42 | protected function meta($model, $user = null): array |
||
46 | |||
47 | private function filterFields(array $data): array |
||
61 | } |
||
62 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: