I'm preforming a query six times to return me multiple result sets. The query is same for all call but the params only vary. It is as follows:
public function getGroupedInfo($id, $type, $zip, $field) {
return DB::table('data')
->select(DB::raw("{$field} as obj, COUNT(*) as count"))
->where('report_id', $id)
->where('book_section', $type)
->where('zip_code', $zip)
->groupBy("{$field}")
->orderBy('count', 'DESC')->get();
}
I'm calling the function as follows:
public function stats(Request $request){
$schools['Elementary Schools'] = $this->getGroupedInfo($id, $listing_type, $zip_code, 'elementary_school');
$schools['Middle Schools'] = $this->getGroupedInfo($id, $listing_type, $zip_code, 'middle_school');
$schools['High Schools'] = $this->getGroupedInfo($id, $listing_type, $zip_code, 'high_school');
$others['lot_sqft'] = $this->getGroupedInfo($id, $listing_type, $zip_code, 'lot_sqft');
}
I was planning on adding them to a single stored procedure, but I'm not sure how to write these in a single stored procedure and then work with the results on Laravel end.
Can you please help me out on this. Thanks in advance.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire