repository = $kegiatan; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(KegiatanUserRequest $request) { $this->repository->pushCriteria(new \Lavalite\Kegiatan\Repositories\Criteria\KegiatanUserCriteria()); $kegiatans = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('kegiatan::kegiatan.names').' :: '); return $this->theme->of('kegiatan::user.kegiatan.index', compact('kegiatans'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Kegiatan $kegiatan * * @return Response */ public function show(KegiatanUserRequest $request, Kegiatan $kegiatan) { Form::populate($kegiatan); return $this->theme->of('kegiatan::user.kegiatan.show', compact('kegiatan'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(KegiatanUserRequest $request) { $kegiatan = $this->repository->newInstance([]); Form::populate($kegiatan); return $this->theme->of('kegiatan::user.kegiatan.create', compact('kegiatan'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(KegiatanUserRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $kegiatan = $this->repository->create($attributes); $this->responseCode = 201; $this->responseMessage = trans('messages.success.created', ['Module' => trans('kegiatan::kegiatan.name')]); $this->responseRedirect = trans_url('/user/kegiatan/kegiatan'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Kegiatan $kegiatan * * @return Response */ public function edit(KegiatanUserRequest $request, Kegiatan $kegiatan) { Form::populate($kegiatan); return $this->theme->of('kegiatan::user.kegiatan.edit', compact('kegiatan'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Kegiatan $kegiatan * * @return Response */ public function update(KegiatanUserRequest $request, Kegiatan $kegiatan) { try { $this->repository->update($request->all(), $kegiatan->getRouteKey()); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('kegiatan::kegiatan.name')]); $this->responseRedirect = trans_url('/user/kegiatan/kegiatan'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(KegiatanUserRequest $request, Kegiatan $kegiatan) { try { $this->repository->delete($kegiatan->getRouteKey()); $this->responseCode = 204; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('kegiatan::kegiatan.name')]); $this->responseRedirect = trans_url('/user/kegiatan/kegiatan'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }