src/Traits/ExportsCollection.php
public function toJSON(Builder $query)
    {
        file_put_contents(
            $file = $this->getFilename(),
            json_encode($this->exportableQuery($query)->get())
        );

        return $this->sendDownloadResponse($file, 'json', ['Content-Type' => 'application/json']);
    }
public function toJSON(Builder $query)
    {
        file_put_contents(
            $file = $this->getFilename(),
            json_encode($this->exportableQuery($query)->get())
        );

        return $this->sendDownloadResponse($file, 'json', ['Content-Type' => 'application/json']);
    }
public function toJSON ( Builder $ query ) { file_put_contents ( $ file = $ this -> getFilename ( ) , json_encode ( $ this -> exportableQuery ( $ query ) -> get ( ) ) ) ; return $ this -> sendDownloadResponse ( $ file , 'json' , [ 'Content-Type' => 'application/json' ] ) ; }
Convert & download collection in JSON format.

@param $query

@return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
Convert & download collection in JSON format .