form = OrderForm::setAttributes()->toArray(); $this->modules = $this->modules(config('ebuy.order.modules'), 'order', guard_url('order')); $this->repository = $order; } /** * Display a list of order. * * @return Response */ public function index(OrderRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(OrderResourceFilter::class) ->setPresenter(OrderListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('order::order.names')) ->view('order::order.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display order. * * @param Request $request * @param Model $order * * @return Response */ public function show(OrderRequest $request, OrderRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('order::order.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('order::order.show') ->output(); } /** * Show the form for creating a new order. * * @param Request $request *x * @return Response */ public function create(OrderRequest $request, OrderRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('order::order.name')) ->view('order::order.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new order. * * @param Request $request * * @return Response */ public function store(OrderRequest $request, OrderRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('order::order.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('order/order/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/order/order')) ->redirect(); } } /** * Show order for editing. * * @param Request $request * @param Model $order * * @return Response */ public function edit(OrderRequest $request, OrderRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('order::order.name')) ->view('order::order.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the order. * * @param Request $request * @param Model $order * * @return Response */ public function update(OrderRequest $request, OrderRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('order::order.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('order/order/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('order/order/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the order. * * @param Model $order * * @return Response */ public function destroy(OrderRequest $request, OrderRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('order::order.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('order/order/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('order/order/' . $repository->getRouteKey())) ->redirect(); } } }