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