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