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