/** * Execute the job. * * @return void */ public function handle(UserRepositoryInterface $userRepo, ShoppingCart $cart) { $data = ['name' => $this->name, 'email' => $this->email, 'phone' => $this->phone, 'address1' => $this->address1, 'address2' => $this->address2, 'city' => $this->city, 'state' => $this->state, 'country' => $this->country]; $user = $userRepo->store($data); if ($user) { /** * Save the data to "bookings" table */ $booking = $user->bookings()->create(['booking_reference' => time(), 'status' => 0, 'comments' => '']); foreach ($cart->contentBooking() as $item) { $packageId = $item->options->package->id; $quantity = $item->qty; $child_quantity = $item->options->child_quantity; /** * Save the data to "booking_details" table */ $booking->packages()->attach($packageId, ['adult_quantity' => $quantity, 'child_quantity' => $child_quantity, 'date' => $item->options->date, 'date_submit' => $item->options->date_submit, 'time' => $item->options->time ?: '']); } $cart->destroyBooking(); event(new UserBookedAPackage($user, $booking->booking_reference)); } else { event(new UserBookingWasNotSuccessful($user)); /** * If payment is unsuccessful, delete the user to avoid duplicating his/her record on the "users" table */ $userRepo->delete($user->id); } }
/** * Execute the job. * * @return void */ public function handle(PackageRepositoryInterface $package, ShoppingCart $cart) { $selectedPackage = $package->find($this->package_id); $newItem = ['id' => $selectedPackage->id, 'name' => $selectedPackage->name, 'qty' => (int) $this->quantity, 'price' => $selectedPackage->adult_price, 'options' => ['child_quantity' => $this->child_quantity, 'date' => $this->date, 'date_submit' => $this->date_submit, 'time' => $this->time ?: '', 'package' => $selectedPackage]]; $cart->add($newItem); return $newItem; }