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