'Manajemen Gejala', 'gejala' => Gejala::get(), 'content' => 'admin/gejala/index' ]; return view('admin.layouts.wrapper', $data); } /** * Show the form for creating a new resource. */ public function create() { $latestGejala = Gejala::orderBy('id', 'desc')->first(); $newId = ($latestGejala ? intval(substr($latestGejala->kode_gejala, 1)) : 0) + 1; $newKodeGejala = "G" . $newId; $data = [ 'title' => 'Tambah Gejala', 'newKodeGejala' => $newKodeGejala, // Mengirim kode gejala baru ke view 'content' => 'admin/gejala/create' ]; return view('admin.layouts.wrapper', $data); } /** * Store a newly created resource in storage. */ public function store(Request $request) { $data = $request->validate([ 'name' => 'required|string|max:255', 'nilai_cf' => 'required|in:0.2,0.4,0.6,0.8,1', ]); $latestGejala = Gejala::orderBy('id', 'desc')->first(); $newId = ($latestGejala ? intval(substr($latestGejala->kode_gejala, 1)) : 0) + 1; // dd($newId); $data['kode_gejala'] = 'G' . $newId; Gejala::create($data); Alert::success('Sukses', 'Data Telah ditambahkan'); return redirect('/admin/gejala'); } /** * Display the specified resource. */ public function show(Gejala $gejala) { // } /** * Show the form for editing the specified resource. */ public function edit(Gejala $gejala) { $data = [ 'title' => 'Edit Gejala', 'gejala' => $gejala, 'content' => 'admin/gejala/edit' ]; return view('admin.layouts.wrapper', $data); } /** * Update the specified resource in storage. */ public function update(Request $request, Gejala $gejala) { $data = $request->validate([ 'name' => 'required|string|max:255', 'nilai_cf' => 'required|in:0.2,0.4,0.6,0.8,1', ]); Gejala::where('id', $gejala->id)->update($data); Alert::success('Sukses', 'Data Telah Diubah!'); return redirect('/admin/gejala'); } /** * Remove the specified resource from storage. */ /** * Remove the specified resource from storage. */ public function destroy(Gejala $gejala) { Gejala::destroy($gejala->id); Alert::success('Sukses', 'Data Telah Dihapus'); return redirect('/admin/gejala'); } }