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