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