repository = $kegiatan; } /** * Display a list of kegiatan. * * @return Response */ public function index(KegiatanAdminRequest $request) { $kegiatans = $this->repository->setPresenter('\\Hilmysyarif\\Kegiatan\\Repositories\\Presenter\\KegiatanListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this ->theme->prependTitle(trans('kegiatan::kegiatan.names').' :: '); $view = $this->theme->of('kegiatan::admin.kegiatan.index')->render(); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('kegiatan::kegiatan.name')]); $this->responseData = $kegiatans['data']; $this->responseMeta = $kegiatans['meta']; $this->responseView = $view; $this->responseRedirect = ''; return $this->respond($request); } /** * Display kegiatan. * * @param Request $request * @param int $id * * @return Response */ public function show(KegiatanAdminRequest $request, Kegiatan $kegiatan) { if (!$kegiatan->exists) { $this->responseCode = 404; $this->responseMessage = trans('messages.success.notfound', ['Module' => trans('kegiatan::kegiatan.name')]); $this->responseView = view('kegiatan::admin.kegiatan.new'); return $this -> respond($request); } Form::populate($kegiatan); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('kegiatan::kegiatan.name')]); $this->responseData = $kegiatan; $this->responseView = view('kegiatan::admin.kegiatan.show', compact('kegiatan')); return $this -> respond($request); } /** * Show the form for creating a new kegiatan. * * @param Request $request * * @return Response */ public function create(KegiatanAdminRequest $request) { $kegiatan = $this->repository->newInstance([]); Form::populate($kegiatan); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('kegiatan::kegiatan.name')]); $this->responseData = $kegiatan; $this->responseView = view('kegiatan::admin.kegiatan.create', compact('kegiatan')); return $this -> respond($request); } /** * Create new kegiatan. * * @param Request $request * * @return Response */ public function store(KegiatanAdminRequest $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->responseData = $kegiatan; $this->responseMeta = ''; $this->responseRedirect = trans_url('/admin/kegiatan/kegiatan/'.$kegiatan->getRouteKey()); $this->responseView = view('kegiatan::admin.kegiatan.create', compact('kegiatan')); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); return $this -> respond($request); } } /** * Show kegiatan for editing. * * @param Request $request * @param int $id * * @return Response */ public function edit(KegiatanAdminRequest $request, Kegiatan $kegiatan) { Form::populate($kegiatan); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('kegiatan::kegiatan.name')]); $this->responseData = $kegiatan; $this->responseView = view('kegiatan::admin.kegiatan.edit', compact('kegiatan')); return $this -> respond($request); } /** * Update the kegiatan. * * @param Request $request * @param int $id * * @return Response */ public function update(KegiatanAdminRequest $request, Kegiatan $kegiatan) { try { $attributes = $request->all(); $kegiatan->update($attributes); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('kegiatan::kegiatan.name')]); $this->responseData = $kegiatan; $this->responseRedirect = trans_url('/admin/kegiatan/kegiatan/'.$kegiatan->getRouteKey()); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/kegiatan/kegiatan/'.$kegiatan->getRouteKey()); return $this -> respond($request); } } /** * Remove the kegiatan. * * @param int $id * * @return Response */ public function destroy(KegiatanAdminRequest $request, Kegiatan $kegiatan) { try { $t = $kegiatan->delete(); $this->responseCode = 202; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('kegiatan::kegiatan.name')]); $this->responseRedirect = trans_url('/admin/kegiatan/kegiatan/0'); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/kegiatan/kegiatan/'.$kegiatan->getRouteKey()); return $this -> respond($request); } } }