middleware('customer'); $this->currentCustomer = auth()->guard('customer')->user(); $this->orderRepository = $orderRepository; $this->invoiceRepository = $invoiceRepository; parent::__construct(); } /** * Display a listing of the resource. * * @return \Illuminate\View\View */ public function index() { return view($this->_config['view']); } /** * Show the view for the specified resource. * * @param int $id * @return \Illuminate\View\View */ public function view($id) { $order = $this->orderRepository->findOneWhere([ 'customer_id' => $this->currentCustomer->id, 'id' => $id, ]); if (! $order) { abort(404); } return view($this->_config['view'], compact('order')); } /** * Print and download the for the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function print($id) { $invoice = $this->invoiceRepository->findOrFail($id); if ($invoice->order->customer_id !== $this->currentCustomer->id) { abort(404); } $pdf = PDF::loadView('shop::customers.account.orders.pdf', compact('invoice'))->setPaper('a4'); return $pdf->download('invoice-' . $invoice->created_at->format('d-m-Y') . '.pdf'); } /** * Cancel action for the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function cancel($id) { /* find by order id in customer's order */ $order = $this->currentCustomer->all_orders()->find($id); /* if order id not found then process should be aborted with 404 page */ if (! $order) { abort(404); } $result = $this->orderRepository->cancel($order); if ($result) { session()->flash('success', trans('admin::app.response.cancel-success', ['name' => 'Order'])); } else { session()->flash('error', trans('admin::app.response.cancel-error', ['name' => 'Order'])); } return redirect()->back(); } }