select(['id','name']) ->get(); $list = []; foreach($restaurants as $restaurant) { $list['restaurant-'.$restaurant->id] = [ 'name' => $restaurant->name, 'bookings' => [] ]; for ($month = 0; $month < 6; $month++){ $y_month = evavel_date_now()->addMonths(-$month)->format('Y-m'); $total = Query::table('bookings') ->where('restaurant_id', $restaurant->id) ->where('date', 'like', $y_month.'%') ->where('status', '!=', \Alexr\Enums\BookingStatus::SELECTED) ->where('status', '!=', \Alexr\Enums\BookingStatus::DELETED) ->count(); $list['restaurant-'.$restaurant->id]['bookings'][$y_month] = $total; } } $data = $list; return $this->response(['success' => true, 'data' => $data]); } }