I need to compare the data in the table by years. For this, I want the user to enter two different years. I want to print the result in the table.
I'm pulling a year's worth of data like this:
$order_detail_model = OrderDetail::whereBetween('created_at', [Carbon::createFromDate($request->get('year1')->startOfYear()),Carbon::createFromDate($request->get('year1')->endOfYear()]);
$order_detail_model = $order_detail_model->with('product')->select('service_id', $order_detail_model->raw('count(*) as total'),$order_detail_model->raw('sum(price) as price'))->groupBy('service_id');
When I print with dd($order_detail_model):

I want to pull data from two different years in the same query like this. Is it possible? Or is there another solution?
Note:Should be in a single query