get('tab')) { return redirect()->route('orders.index', ['tab' => 'all']); } return view('orders.index', [ 'tab' => $request->get('tab'), ]); } public function create() { return view('orders.create', [ 'order_types' => OrderType::cases(), 'order_status' => OrderStatus::cases(), 'customers' => Customer::all(), 'today' => Carbon::today()->format('Y-m-d'), 'due_default' => Carbon::today()->addDay(10)->format('Y-m-d'), ]); } public function store(OrderRequest $request) { // Create order $order = Order::create($request->safe()->only([ 'customer_id', 'contact_id', 'order_type', 'status', 'customer_po', 'order_date', 'due_date', 'rush', 'new_art', 'digitizing', 'repeat', 'purchased_garments', 'customer_supplied_file', 'notes', ])); // Create orderProducts for ($i = 0; $i < count($request->get('productInputCount')) - 1; $i++) { $orderProduct = OrderProduct::create([ 'order_id' => $order->id, 'sku' => $request->get('sku')[$i], 'product_name' => $request->get('product_name')[$i], 'color' => $request->get('product_color')[$i], ]); // Create productSizes foreach (['xs', 's', 'm', 'l', 'xl', '2xl', '3xl', 'osfa'] as $size) { ProductSize::create([ 'order_product_id' => $orderProduct->id, 'amount' => $request->get('size_'.$size)[$i], 'size' => $size, ]); } } // Create productServices for ($i = 0; $i < count($request->get('serviceInputCount')) - 1; $i++) { $serviceFile = ServiceFile::create([ 'code' => $request->get('service_file_name')[$i], 'name' => $request->get('logo_name')[$i], 'width' => $request->get('service_width')[$i], 'height' => $request->get('service_height')[$i], 'setup_number' => $request->get('setup_amount')[$i], ]); ProductService::create([ 'order_id' => $order->id, 'service_file_id' => $serviceFile->id, 'service_type' => $request->get('service_type')[$i], 'placement' => $request->get('placement')[$i], 'amount' => $request->get('amount')[$i], 'amount_price' => $request->get('amount_price')[$i], 'notes' => $request->get('service_notes')[$i], ]); } return redirect()->route('orders.show', $order); } public function show(int $id): Factory|\Illuminate\Contracts\View\View|Application|View { return view('orders.show', [ 'order' => Order::find($id), 'tab' => 'details', ]); } public function edit(int $id) {} public function update(Request $request, $id) {} public function destroy(int $id): void {} public function pdf(int $id) { $order = Order::find($id); $url = strtolower('order-'.$order->internal_po.'.pdf'); Pdf::view('pdf.order', ['order' => $order]) ->withBrowsershot(function (Browsershot $browsershot) { $browsershot->noSandbox(); }) ->margins(8, 8, 15, 8) ->footerView('pdf.order-footer', ['order' => $order]) ->save($url); return redirect($url); } }