I am trying to merge two queries
$sales = DB::table('sales')
->join('drugs', 'drugs.id', '=', 'sales.drug_id')
->select('sales.*','drugs.name', DB::raw('sum(sales.quantity_sold) as total_sales'))
->whereYear('date_sold','>','2014')
->whereYear('date_sold','<','2017')
->get()->groupBy('sales.drug_id');
$stocks = DB::table('sales')
->join('drugs', 'drugs.id', '=', 'sales.drug_id')
->select('sales.*','drugs.name', DB::raw ('AVG(sales.quantity_sold) as average_sales'))
->whereMonth('date_sold','=', Carbon::today()->month)
->get()->groupBy('sales.drug_id');
$data = $stocks->merge($sales);
I get an error, Call to a member function groupBy() on a non-object. Any help?
astroanu said:
try calling groupBy() before the get() instead of after
still doesn't work.. error Call to a member function merge() on a non-object
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community