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