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