public function getVespaString() { $vespasName = []; $vespas = json_decode($this->vespa, true); foreach ($vespas as $vespa) { $v = Vespa::find($vespa['code']); for ($i = 0; $i < $vespa['amount']; $i++) { array_push($vespasName, $v->name); } } return implode('<br>', $vespasName); // return $this->vespa; }
public function store(Request $request, DateService $dateService, PricingService $pricingService) { // $vesp = json_decode($request->input('vespa'),true); // dd($request->input()); $pickupDate = $dateService->getCarbonDateFromDateString($request->input('pickupDate'), 'Y-m-d H:i:s'); // dd($pickupDate); $returnDate = $dateService->getCarbonDateFromDateString($request->input('returnDate'), 'Y-m-d H:i:s'); // Calculate Price $price = $pricingService->getPriceCalculation($pickupDate, $returnDate, $request->input('quantity')); $vespas = json_decode($request->input('vespa'), true); $vespasName = []; foreach ($vespas as $vespa) { $v = Vespa::find($vespa['code']); $initStock = $v->stock; $stock = $initStock - $vespa['amount']; $v->stock = $stock; $v->save(); // dd($vespa['code']); array_push($vespasName, $v->name); } BookingHistory::create(['name' => $request->input('name'), 'phone' => $request->input('phone'), 'email' => $request->input('email'), 'comment' => $request->input('comment'), 'vespa' => $request->input('vespa'), 'pickup_time' => $request->input('pickupDate'), 'return_time' => $request->input('returnDate'), 'quantity' => $request->input('quantity'), 'price' => $price]); return redirect()->route('book.thankyou'); }
/** * Run the database seeds. * * @return void */ public function run() { Vespa::truncate(); Vespa::create(['name' => 'Vespa PX123', 'code' => 'px123', 'status' => 0]); Vespa::create(['name' => 'Vespa ASDF1234', 'code' => 'asdf1234', 'status' => 0]); }