model = $pnddk; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(PnddkAdminRequest $request) { if ($request->wantsJson()) { $array = $this->model->json(); foreach ($array as $key => $row) { $array[$key] = array_only($row, config('desa.pnddk.listfields')); } return ['data' => $array]; } $this->theme->prependTitle(trans('desa::pnddk.names').' :: '); return $this->theme->of('desa::admin.pnddk.index')->render(); } /** * Display the specified resource. * * @param Request $request * @param int $id * * @return Response */ public function show(PnddkAdminRequest $request, $id) { $pnddk = $this->model->find($id); if (empty($pnddk)) { if ($request->wantsJson()) { return []; } return view('desa::admin.pnddk.new'); } if ($request->wantsJson()) { return $pnddk; } Former::populate($pnddk); return view('desa::admin.pnddk.show', compact('pnddk')); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(PnddkAdminRequest $request) { $pnddk = $this->model->findOrNew(0); Former::populate($pnddk); return view('desa::admin.pnddk.create', compact('pnddk')); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(PnddkAdminRequest $request) { try { $attributes = $request->all(); $pnddk = $this->model->create($attributes); return $this->success(trans('messages.success.created', ['Module' => trans('desa::pnddk.name')])); } catch (Exception $e) { return $this->error($e->getMessage()); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param int $id * * @return Response */ public function edit(PnddkAdminRequest $request, $id) { $pnddk = $this->model->find($id); Former::populate($pnddk); return view('desa::admin.pnddk.edit', compact('pnddk')); } /** * Update the specified resource. * * @param Request $request * @param int $id * * @return Response */ public function update(PnddkAdminRequest $request, $id) { try { $attributes = $request->all(); $pnddk = $this->model->update($attributes, $id); return $this->success(trans('messages.success.updated', ['Module' => trans('desa::pnddk.name')])); } catch (Exception $e) { return $this->error($e->getMessage()); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(PnddkAdminRequest $request, $id) { try { $this->model->delete($id); return $this->success(trans('message.success.deleted', ['Module' => trans('desa::pnddk.name')]), 200); } catch (Exception $e) { return $this->error($e->getMessage()); } } }