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