/** * Get all of the products of a given Breeder * * @param Breeder $breeder * @return Collection */ public function forBreeder(Breeder $breeder) { $products = $breeder->products()->where('status', 'requested')->get(); $reservations = $breeder->reservations()->get(); $items = []; // Include all "requested" products foreach ($products as $product) { if ($product->quantity == 0) { continue; } $itemDetail = []; $itemDetail['uuid'] = (string) Uuid::uuid4(); $itemDetail['id'] = $product->id; $itemDetail['reservation_id'] = 0; $itemDetail['img_path'] = '/images/product/' . Image::find($product->primary_img_id)->name; $itemDetail['breeder_id'] = $product->breeder_id; $itemDetail['farm_province'] = FarmAddress::find($product->farm_from_id)->province; $itemDetail['name'] = $product->name; $itemDetail['type'] = $product->type; $itemDetail['age'] = $this->computeAge($product->birthdate); $itemDetail['breed'] = $this->transformBreedSyntax(Breed::find($product->breed_id)->name); $itemDetail['quantity'] = $product->quantity; $itemDetail['adg'] = $product->adg; $itemDetail['fcr'] = $product->fcr; $itemDetail['bft'] = $product->backfat_thickness; $itemDetail['status'] = $product->status; $itemDetail['customer_id'] = 0; $itemDetail['customer_name'] = ''; $itemDetail['date_needed'] = ''; $itemDetail['special_request'] = ''; array_push($items, (object) $itemDetail); } // Include "reserved" / "paid" / "on_delivery" / "sold" products foreach ($reservations as $reservation) { $product = Product::find($reservation->product_id); $itemDetail = []; $itemDetail['uuid'] = (string) Uuid::uuid4(); $itemDetail['id'] = $product->id; $itemDetail['reservation_id'] = $reservation->id; $itemDetail['img_path'] = '/images/product/' . Image::find($product->primary_img_id)->name; $itemDetail['breeder_id'] = $product->breeder_id; $itemDetail['farm_province'] = FarmAddress::find($product->farm_from_id)->province; $itemDetail['name'] = $product->name; $itemDetail['type'] = $product->type; $itemDetail['age'] = $this->computeAge($product->birthdate); $itemDetail['breed'] = $this->transformBreedSyntax(Breed::find($product->breed_id)->name); $itemDetail['quantity'] = $reservation->quantity; $itemDetail['adg'] = $product->adg; $itemDetail['fcr'] = $product->fcr; $itemDetail['bft'] = $product->backfat_thickness; $itemDetail['status'] = $reservation->order_status; $itemDetail['customer_id'] = $reservation->customer_id; $itemDetail['customer_name'] = Customer::find($reservation->customer_id)->users()->first()->name; $itemDetail['date_needed'] = $this->transformDateSyntax($reservation->date_needed); $itemDetail['special_request'] = $reservation->special_request; array_push($items, (object) $itemDetail); } // dd($items); return collect($items)->toJson(); }