Laravel Slow queries Laravel Slow queries laravel laravel

Laravel Slow queries


try to delete the record without loading it:

public function delete( ReportDetailRequest $request ){       $customerRecord = CustomerInfo::where('id',$request->id)->delete();    }

please note that you don't have to cast $request->id to int


You don't need to fetch record from db to remove it

public function delete( ReportDetailRequest $request ){       return CustomerInfo::where('id',$request->input('id'))->delete();    // it will return the count of deleted rows}


The main reason for the response to be slow is that DB is being called two times one to find records and then to delete. Instead, you should do it like this. This would be also great when deleting a large no. of records.

$ids = explode(",", $id);CustomerInfo::whereIn('id', $ids)->delete();