Controllers\Api\Exports::showJson PHP Method

showJson() public method

Exports statements as JSON.
public showJson ( String $id ) : StreamedResponse.
$id String Export's ID.
return StreamedResponse.
    public function showJson($id)
    {
        // should top timeouts on long queries
        set_time_limit(0);
        $opts = $this->getOptions();
        $model = $this->repo->show($id, $opts);
        return IlluminateResponse::stream(function () use($model, $opts) {
            if (ob_get_level() == 0) {
                ob_start();
            }
            echo '[';
            $this->repo->export($model, array_merge($opts, ['next' => function () {
                echo ',';
                flush();
                ob_flush();
            }, 'stream' => function ($obj) {
                echo json_encode($obj);
            }]));
            echo ']';
        }, 200, ['Content-Type' => 'application/json']);
    }