/** * Create instance from reques * * @param string $method * @param null|int|string $id * @param array|\Illuminate\Contracts\Support\Arrayable $params * @return $this|array */ protected static function instanceFromRequest($method, $id = null, $params = []) { $response = static::requestToArray($method, $id, $params); if (Arr::isAssoc($response)) { return new static($response); } return Collection::makeOf(static::class, $response); }
public static function all($params = []) { $metadata = []; $response = static::requestToArray('GET', null, $params); if (Arr::has($response, 'metadata')) { $metadata = Arr::pull($response, 'metadata'); $response = Arr::pull($response, 'data'); } // Create collection of current class $collection = Collection::makeOf(static::class, $response); // Set metada property to main object foreach ($metadata as $key => $value) { $collection->{$key} = $value; } return $collection; }