middleware(function ($request, $next) { $this->form = CustomerForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('crm.customer.modules'), 'customer', guard_url('customer')); return $next($request); }); } /** * Display a list of customer. * * @return Response */ public function index(CustomerResourceRequest $request) { $request = $request->all(); $page = CustomerActions::run('paginate', $request); $data = new CustomersCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('customer::customer.names')) ->view('customer::customer.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display customer. * * @param Request $request * @param Model $customer * * @return Response */ public function show(CustomerResourceRequest $request, Customer $model) { $form = $this->form; $modules = $this->modules; $data = new CustomerResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('customer::customer.name')) ->data(compact('data', 'form', 'modules')) ->view('customer::customer.show') ->output(); } /** * Show the form for creating a new customer. * * @param Request $request * * @return Response */ public function create(CustomerResourceRequest $request, Customer $model) { $form = $this->form; $modules = $this->modules; $data = new CustomerResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('customer::customer.name')) ->view('customer::customer.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new customer. * * @param Request $request * * @return Response */ public function store(CustomerResourceRequest $request, Customer $model) { try { $request = $request->all(); $model = CustomerAction::run('store', $model, $request); $data = new CustomerResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('customer::customer.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('customer/customer/' . $model->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(CustomerResourceRequest $request, Customer $model) { $form = $this->form; $modules = $this->modules; $data = new CustomerResource($model); // return view('customer::customer.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('customer::customer.name')) ->view('customer::customer.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the customer. * * @param Request $request * @param Model $customer * * @return Response */ public function update(CustomerResourceRequest $request, Customer $model) { try { $request = $request->all(); $model = CustomerAction::run('update', $model, $request); $data = new CustomerResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('customer::customer.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('customer/customer/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('customer/customer/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the customer. * * @param Model $customer * * @return Response */ public function destroy(CustomerResourceRequest $request, Customer $model) { try { $request = $request->all(); $model = CustomerAction::run('destroy', $model, $request); $data = new CustomerResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('customer::customer.name')])) ->code(202) ->status('success') ->data(compact('data')) ->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/' . $model->getRouteKey())) ->redirect(); } } }