diff --git a/app/Http/Controllers/PeriodeController.php b/app/Http/Controllers/PeriodeController.php index 91a7abb..10c0768 100644 --- a/app/Http/Controllers/PeriodeController.php +++ b/app/Http/Controllers/PeriodeController.php @@ -49,7 +49,7 @@ class PeriodeController extends Controller $periode->is_active = 0; } - if(!$periode->save()){ + if($periode->save()){ return redirect()->route('periode.index')->with([ 'type' => 'success', 'msg' => 'Periode baru ditambahkan' @@ -62,26 +62,15 @@ class PeriodeController extends Controller } } - /** - * Display the specified resource. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function show($id) - { - // - } - /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ - public function edit($id) + public function edit(Periode $periode) { - // + return view('periode.form', ['periode' => $periode]); } /** @@ -91,9 +80,32 @@ class PeriodeController extends Controller * @param int $id * @return \Illuminate\Http\Response */ - public function update(Request $request, $id) + public function update(Request $request, Periode $periode) { - // + $request->validate([ + 'nama' => 'required|max:255', + 'tgl_mulai' => 'required|date|before:'.$request->tgl_selesai, + 'tgl_selesai' => 'required|date', + 'is_active' => 'nullable|boolean', + ]); + + $periode->fill($request->input()); + + if($request->is_active == null){ + $periode->is_active = 0; + } + + if($periode->save()){ + return redirect()->route('periode.index')->with([ + 'type' => 'success', + 'msg' => 'Periode berhasil diubah' + ]); + }else{ + return redirect()->route('periode.index')->with([ + 'type' => 'danger', + 'msg' => 'Err.., Terjadi Kesalahan' + ]); + } } /** @@ -102,8 +114,18 @@ class PeriodeController extends Controller * @param int $id * @return \Illuminate\Http\Response */ - public function destroy($id) + public function destroy(Periode $periode) { - // + if($periode->delete()){ + return redirect()->route('periode.index')->with([ + 'type' => 'success', + 'msg' => 'Periode telah dihapus' + ]); + }else{ + return redirect()->route('periode.index')->with([ + 'type' => 'danger', + 'msg' => 'Err.., Terjadi Kesalahan' + ]); + } } } diff --git a/resources/views/periode/form.blade.php b/resources/views/periode/form.blade.php index be1370b..e56f455 100644 --- a/resources/views/periode/form.blade.php +++ b/resources/views/periode/form.blade.php @@ -23,23 +23,23 @@ @csrf
- +
- +
- +
Status
@@ -63,7 +63,7 @@ $(document).ready(function () { $('[data-toggle="datepicker"]').datepicker({ - format: 'yyyy/MM/dd' + format: 'yyyy-MM-dd' }); }); diff --git a/resources/views/periode/index.blade.php b/resources/views/periode/index.blade.php index 87fb4fb..9952975 100644 --- a/resources/views/periode/index.blade.php +++ b/resources/views/periode/index.blade.php @@ -51,10 +51,12 @@ {{ $item->tgl_selesai }} - {{ $item->is_active }} + @if($item->is_active) + Aktif + @endif - + diff --git a/routes/web.php b/routes/web.php index b849a18..28e3714 100644 --- a/routes/web.php +++ b/routes/web.php @@ -31,7 +31,6 @@ Route::middleware(['auth:web'])->group(function(){ Route::get('periode','PeriodeController@index')->name('periode.index'); Route::get('tambah-periode','PeriodeController@create')->name('periode.create'); Route::post('tambah-periode', 'PeriodeController@store')->name('periode.store'); - Route::get('periode/{periode}/detail', 'PeriodeController@show')->name('periode.show'); Route::get('periode/{periode}/ubah', 'PeriodeController@edit')->name('periode.edit'); Route::post('periode/{periode}/ubah','PeriodeController@update')->name('periode.update'); Route::post('periode/{periode}/hapus', 'PeriodeController@destroy')->name('periode.destroy');