middleware(function ($request, $next) { $this->form = CustomerForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('bixo.account.modules'), 'account', guard_url('account')); 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('account::customer.names')) ->view('account::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('account::customer.name')) ->data(compact('data', 'form', 'modules')) ->view('account::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('account::customer.name')) ->view('account::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('account::customer.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('account/customer/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/account/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('account::customer.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('account::customer.name')) ->view('account::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('account::customer.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('account/customer/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('account/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('account::customer.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('account/customer/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('account/customer/' . $model->getRouteKey())) ->redirect(); } } }