Laravel\Lumen\Http\ResponseFactory::json PHP Method

json() public method

Return a new JSON response from the application.
public json ( string | array $data = [], integer $status = 200, array $headers = [], integer $options ) : Illuminate\Http\JsonResponse;
$data string | array
$status integer
$headers array
$options integer
return Illuminate\Http\JsonResponse;
    public function json($data = [], $status = 200, array $headers = [], $options = 0)
    {
        if ($data instanceof Arrayable) {
            $data = $data->toArray();
        }
        return new JsonResponse($data, $status, $headers, $options);
    }

Usage Example

Esempio n. 1
0
 /**
  * Generic response.
  *
  * @api
  * @param array|null $payload
  * @return \Illuminate\Contracts\Http\Response
  */
 public function respond($payload)
 {
     if ($meta = $this->getMeta()) {
         $payload = array_merge($payload, ['meta' => $meta]);
     }
     return !($callback = $this->request->input('callback')) ? $this->response->json($payload, $this->getStatusCode(), $this->getHeaders()) : $this->response->jsonp($callback, $payload, $this->getStatusCode(), $this->getHeaders());
 }
All Usage Examples Of Laravel\Lumen\Http\ResponseFactory::json