Returning millions of records from api response laravel

Viewed 30

I have a requirement where i am supposed to return millions of records from my database when an api endpoint is being called. As per requirement, pagination is being done on the frontend so returning paginated data is not an option. I have tried this;

$this->employee_records = DB::table('master_data')->select(DB::raw("employee_number, first_name, middle_name, last_name, ministry, grade, original_date_of_hire, provider_name, pfa_name, date_of_birth"))->orderBy('first_name')->cursor();

But the load time is still in minutes. How can i optimize this? Thanks

1 Answers
Related