/** * Get the statuses of the products of a Breeder * Include hidden, displayed, requested, * reserved, paid, on_delivery, * and sold quantity * * @param Breeder $breeder * @return Array */ public function getProductStatus(Breeder $breeder, $status) { if ($status == 'hidden' || $status == 'displayed' || $status == 'requested') { $products = $breeder->products; $overallQuery = $products->where('status', $status); $boarQuery = $products->where('status', $status)->where('type', 'boar'); $sowQuery = $products->where('status', $status)->where('type', 'sow'); $giltQuery = $products->where('status', $status)->where('type', 'gilt'); $semenQuery = $products->where('status', $status)->where('type', 's***n'); return ['overall' => $overallQuery->count(), 'boar' => $boarQuery->count(), 'sow' => $sowQuery->count(), 'gilt' => $giltQuery->count(), 's***n' => $semenQuery->count()]; } else { // $reservations = ProductReservation::with('product')->get(); $reservations = $breeder->reservations()->with('product')->get(); foreach ($reservations as $reservation) { $reservation->type = $reservation->product->type; } $overallQuery = $reservations->where('order_status', $status); $boarQuery = $reservations->where('order_status', $status)->where('type', 'boar'); $sowQuery = $reservations->where('order_status', $status)->where('type', 'sow'); $giltQuery = $reservations->where('order_status', $status)->where('type', 'gilt'); $semenQuery = $reservations->where('order_status', $status)->where('type', 's***n'); return ['overall' => $overallQuery->count(), 'boar' => $boarQuery->count(), 'sow' => $sowQuery->count(), 'gilt' => $giltQuery->count(), 's***n' => $semenQuery->count()]; } }