Good day guys! this from the previous developer codes and I want to optimize this one because it's have error in fetching data. Anyone has suggestions to optimize this code?
public function render()
{
$dateFrom = $this->dateFrom;
$dateTo = $this->dateTo;
$serviceInvoiceQuery = DB::table('transaction_summaries AS ts')
->select(
'ts.id',
'ts.wv_invoice_no',
'ts.sb_invoice_no',
'ts.all_total_debits',
'ts.all_total_credits',
'ts.transaction_status_id',
'jo.jo_no',
'cp.name',
'transac_stat.name AS transac_stat_name',
'transac_stat.id AS transac_stat_id',
'st.status AS status_name',
'st.id AS status_id',
)
->leftJoin('job_orders AS jo', 'ts.jo_no', '=', 'jo.id')
->leftJoin('client_profiles AS cp', 'jo.customer_id', '=', 'cp.id')
->leftJoin('transaction_statuses AS transac_stat', 'ts.transaction_status_id', '=', 'transac_stat.id')
->leftJoin('statuses AS st', 'ts.status_id', '=', 'st.id')
->where('ts.transaction_type_id', '=', EnumsServiceInvoice::SERVICE_INVOICE)
->orderBy('ts.created_at', 'DESC');
if (!empty($this->search)) {
$serviceInvoiceQuery->where(function ($query) use ($dateFrom, $dateTo) {
if (!is_null($dateFrom) && !is_null($dateTo)) {
$dateFrom = Carbon::parse($this->dateFrom);
$dateTo = Carbon::parse($this->dateTo)->addHour(23)->addMinute(59)->addSecond(59);
$query->where('ts.created_at', '>=', $dateFrom)
->where('ts.created_at', '<=', $dateTo);
}
$query->where(function ($query) {
$query->where('ts.wv_invoice_no', 'LIKE', '%' . $this->search . '%')
->orWhere('ts.sb_invoice_no', 'LIKE', '%' . $this->search . '%')
->orWhere('jo.jo_no', 'LIKE', '%' . $this->search . '%')
->orWhere('cp.name', 'LIKE', '%' . $this->search . '%');
});
});
} else {
if (!is_null($dateFrom) && !is_null($dateTo)) {
$dateFrom = Carbon::parse($this->dateFrom);
$dateTo = Carbon::parse($this->dateTo)->addHour(23)->addMinute(59)->addSecond(59);
$serviceInvoiceQuery->where('ts.created_at', '>=', $dateFrom)
->where('ts.created_at', '<=', $dateTo);
}
}
$serviceInvoice = collect();
$serviceInvoiceQuery->chunk(100, function ($results) use (&$serviceInvoice) {
$serviceInvoice = $serviceInvoice->merge($results);
});
$serviceInvoice = $serviceInvoiceQuery->paginate(10);
return view('livewire.billing.service-invoice-table', [
'serviceInvoice' => $serviceInvoice,
]);
}
The setup is that our client was using wamp for there server since it was just offline and there are only 4 users using the app.
and I already tried this in my php.ini
memory_limit = 4096M but the problem still occures