repository = $customer; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Focus\Focus\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(\Focus\Focus\Repositories\Presenter\CustomerPresenter::class) ->$function(); } $customers = $this->repository->paginate(); return $this->response->title(trans('focus::customer.names')) ->view('focus::customer.index', true) ->data(compact('customers')) ->output(); } /** * Display customer. * * @param Request $request * @param Model $customer * * @return Response */ public function show(CustomerRequest $request, Customer $customer) { if ($customer->exists) { $view = 'focus::customer.show'; } else { $view = 'focus::customer.new'; } return $this->response->title(trans('app.view') . ' ' . trans('focus::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->title(trans('app.new') . ' ' . trans('focus::customer.name')) ->view('focus::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('focus::customer.name')])) ->code(204) ->status('success') ->url(guard_url('focus/customer/' . $customer->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/focus/customer')) ->redirect(); } } /** * Show customer for editing. * * @param Request $request * @param Model $customer * * @return Response */ public function edit(CustomerRequest $request, Customer $customer) { return $this->response->title(trans('app.edit') . ' ' . trans('focus::customer.name')) ->view('focus::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('focus::customer.name')])) ->code(204) ->status('success') ->url(guard_url('focus/customer/' . $customer->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('focus/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('focus::customer.name')])) ->code(202) ->status('success') ->url(guard_url('focus/customer/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('focus/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('focus::customer.name')])) ->status("success") ->code(202) ->url(guard_url('focus/customer')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/focus/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('focus::customer.name')])) ->status("success") ->code(202) ->url(guard_url('/focus/customer')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/focus/customer/')) ->redirect(); } } }