repository = $company; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Survey\Company\Repositories\Criteria\CompanyResourceCriteria::class); } /** * Display a list of company. * * @return Response */ public function index(CompanyRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Survey\Company\Repositories\Presenter\CompanyPresenter::class) ->$function(); } $companies = $this->repository->paginate(); return $this->response->setMetaTitle(trans('company::company.names')) ->view('company::company.index', true) ->data(compact('companies', 'view')) ->output(); } /** * Display company. * * @param Request $request * @param Model $company * * @return Response */ public function show(CompanyRequest $request, Company $company) { if ($company->exists) { $view = 'company::company.show'; } else { $view = 'company::company.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('company::company.name')) ->data(compact('company')) ->view($view, true) ->output(); } /** * Show the form for creating a new company. * * @param Request $request * * @return Response */ public function create(CompanyRequest $request) { $company = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('company::company.name')) ->view('company::company.create', true) ->data(compact('company')) ->output(); } /** * Create new company. * * @param Request $request * * @return Response */ public function store(CompanyRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $company = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('company::company.name')])) ->code(204) ->status('success') ->url(guard_url('company/company/' . $company->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(CompanyRequest $request, Company $company) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('company::company.name')) ->view('company::company.edit', true) ->data(compact('company')) ->output(); } /** * Update the company. * * @param Request $request * @param Model $company * * @return Response */ public function update(CompanyRequest $request, Company $company) { try { $attributes = $request->all(); $company->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('company::company.name')])) ->code(204) ->status('success') ->url(guard_url('company/company/' . $company->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('company/company/' . $company->getRouteKey())) ->redirect(); } } /** * Remove the company. * * @param Model $company * * @return Response */ public function destroy(CompanyRequest $request, Company $company) { try { $company->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('company::company.name')])) ->code(202) ->status('success') ->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/' . $company->getRouteKey())) ->redirect(); } } /** * Remove multiple company. * * @param Model $company * * @return Response */ public function delete(CompanyRequest $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('company::company.name')])) ->status("success") ->code(202) ->url(guard_url('company/company')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/company/company')) ->redirect(); } } /** * Restore deleted companies. * * @param Model $company * * @return Response */ public function restore(CompanyRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('company::company.name')])) ->status("success") ->code(202) ->url(guard_url('/company/company')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/company/company/')) ->redirect(); } } }