$this->id, 'name' => $this->first_name . ' ' . $this->last_name, 'email' => $this->email, 'children' => $this->whenLoaded('children', function () { return TestUserApiResource::collection($this->children); }), ]; if ($this['state1'] && $this['random-state']) { $result['state1'] = $this['state1']; $result['random-state'] = $this['random-state']; } return $result; } }