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