Backend Laravel PHP

How to return large json file on laravel?

We could have some cases which should fetch large json for DB records.

On laravel, we can simple following as:


But if the records are large, it will have a lot of ram on server.

Also if there are a lot of requests, it will be more problems.

So, we can solve following as:

  1. use laravel chunk ( please check official documentation for chunk )
  2. create a json file and append the records in chunk iterator.
  3. return the json file instead of returning to a large collection.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *