Larabros\Elogram\Http\Response::getRaw PHP Method

getRaw() public method

Gets the JSON-decoded raw response.
public getRaw ( string | null $key = null ) : array
$key string | null
return array
    public function getRaw($key = null)
    {
        return $key === null ? $this->raw : $this->raw[$key];
    }

Usage Example

Example #1
0
 /**
  * Merges the contents of this response with ``$response`` and returns a new
  * :php:class:`Response` instance.
  *
  * @param Response $response
  *
  * @return Response
  *
  * @throws IncompatibleResponseException
  */
 public function merge(Response $response)
 {
     $meta = $response->getRaw('meta');
     $data = $response->get();
     $pagination = $response->hasPages() ? $response->getRaw('pagination') : [];
     $old = $this->get();
     if ($this->isCollection($old) && $this->isCollection($data)) {
         $old = !$old instanceof Collection ?: $old->toArray();
         $new = !$data instanceof Collection ?: $data->toArray();
         return new Response($meta, array_merge($old, $new), $pagination);
     }
     if ($this->isRecord($old) && $this->isRecord($data)) {
         return new Response($meta, [$old, $data], $pagination);
     }
     throw new IncompatibleResponseException('The response contents cannot be merged');
 }