I'm using DB::select to query data, and then change it to collection and then download.
The problem is, if there's a date in my where statement, even if it was hardcoded in the query, it failed to download the excel and returns This site can’t be reached error (ERR_INVALID_RESPONSE). If there's no date in where statement, the excel can be download successfully.
Here's my code. For brevity, I omit columns in select statement.
This code works.
$q = DB::select("
SELECT
*
FROM
edukasi_ihprepaid_master
LEFT JOIN areas ON edukasi_ihprepaid_master.cwitel = areas.cwitel
LEFT JOIN users ON edukasi_ihprepaid_master.user_call = users.id
LEFT JOIN hasil_call_ihprepaid ON edukasi_ihprepaid_master.hcall_id = hasil_call_ihprepaid.id
WHERE
edukasi_ihprepaid_master.user_call = 60
AND hcall_id = 1
);
$collection = collect($q);
return (new FastExcel($collection))->download('ihprepaid_reports.xlsx');
While this codes don't work because there's a date filter in where statement.
$q = DB::select("
SELECT
*
FROM
edukasi_ihprepaid_master
LEFT JOIN areas ON edukasi_ihprepaid_master.cwitel = areas.cwitel
LEFT JOIN users ON edukasi_ihprepaid_master.user_call = users.id
LEFT JOIN hasil_call_ihprepaid ON edukasi_ihprepaid_master.hcall_id = hasil_call_ihprepaid.id
WHERE
edukasi_ihprepaid_master.user_call = 60
AND hcall_id = 1
AND tgl_call::date BETWEEN '2022-01-11'
AND '2022-01-12'"
);
$collection = collect($q);
return (new FastExcel($collection))->download('ihprepaid_reports.xlsx');
I'm using DB::select to query data, and then change it to collection and then download. The problem is, if there's a date in my where statement, even if it was hardcoded in the query, it failed to download the excel and returns This site can’t be reached error (ERR_INVALID_RESPONSE). If there's no date in where statement, the excel can be download successfully.
Here's my code. For brevity, I omit columns in select statement.
This code works.
While this codes don't work because there's a date filter in where statement.