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