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