1$data = Inspector::latest('id')
2 ->select('id', 'firstname', 'status', 'state', 'phone')
3 ->where('firstname', 'LIKE', '%' . $searchtext . '%')
4 ->chunk(50, function($inspectors) {
5 foreach ($inspectors as $inspector) {
6 // apply some action to the chunked results here
7 }
8 });