repository = $order; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Laraecart\Cart\Repositories\Criteria\OrderResourceCriteria::class); } /** * Display a list of order. * * @return Response */ public function index(OrderRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Laraecart\Cart\Repositories\Presenter\OrderPresenter::class) ->$function(); } $orders = $this->repository->paginate(); return $this->response->setMetaTitle(trans('cart::order.names')) ->view('cart::order.index', true) ->data(compact('orders', 'view')) ->output(); } /** * Display order. * * @param Request $request * @param Model $order * * @return Response */ public function show(OrderRequest $request, Order $order) { if ($order->exists) { $view = 'cart::order.show'; } else { $view = 'cart::order.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('cart::order.name')) ->data(compact('order')) ->view($view, true) ->output(); } /** * Show the form for creating a new order. * * @param Request $request * * @return Response */ public function create(OrderRequest $request) { $order = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('cart::order.name')) ->view('cart::order.create', true) ->data(compact('order')) ->output(); } /** * Create new order. * * @param Request $request * * @return Response */ public function store(OrderRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $order = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('cart::order.name')])) ->code(204) ->status('success') ->url(guard_url('cart/order/' . $order->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/cart/order')) ->redirect(); } } /** * Show order for editing. * * @param Request $request * @param Model $order * * @return Response */ public function edit(OrderRequest $request, Order $order) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('cart::order.name')) ->view('cart::order.edit', true) ->data(compact('order')) ->output(); } /** * Update the order. * * @param Request $request * @param Model $order * * @return Response */ public function update(OrderRequest $request, Order $order) { try { $attributes = $request->all(); $order->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('cart::order.name')])) ->code(204) ->status('success') ->url(guard_url('cart/order/' . $order->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('cart/order/' . $order->getRouteKey())) ->redirect(); } } /** * Remove the order. * * @param Model $order * * @return Response */ public function destroy(OrderRequest $request, Order $order) { try { $order->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('cart::order.name')])) ->code(202) ->status('success') ->url(guard_url('cart/order/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('cart/order/' . $order->getRouteKey())) ->redirect(); } } /** * Remove multiple order. * * @param Model $order * * @return Response */ public function delete(OrderRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('cart::order.name')])) ->status("success") ->code(202) ->url(guard_url('cart/order')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/cart/order')) ->redirect(); } } /** * Restore deleted orders. * * @param Model $order * * @return Response */ public function restore(OrderRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('cart::order.name')])) ->status("success") ->code(202) ->url(guard_url('/cart/order')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/cart/order/')) ->redirect(); } } }