complate module periode

pull/1/head
Aji Kamaludin 6 years ago
parent f3fb9fd45b
commit 1ab2e2f142
No known key found for this signature in database
GPG Key ID: 23E2BDC458317AF8

@ -49,7 +49,7 @@ class PeriodeController extends Controller
$periode->is_active = 0; $periode->is_active = 0;
} }
if(!$periode->save()){ if($periode->save()){
return redirect()->route('periode.index')->with([ return redirect()->route('periode.index')->with([
'type' => 'success', 'type' => 'success',
'msg' => 'Periode baru ditambahkan' '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. * Show the form for editing the specified resource.
* *
* @param int $id * @param int $id
* @return \Illuminate\Http\Response * @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 * @param int $id
* @return \Illuminate\Http\Response * @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 * @param int $id
* @return \Illuminate\Http\Response * @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'
]);
}
} }
} }

@ -23,23 +23,23 @@
@csrf @csrf
<div class="form-group"> <div class="form-group">
<label class="form-label">Nama</label> <label class="form-label">Nama</label>
<input type="text" class="form-control" name="nama" placeholder="Nama" required> <input type="text" class="form-control" name="nama" placeholder="Nama" value="{{ isset($periode) ? $periode->nama : old('nama') }}" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="form-label">Tanggal Mulai s/d Selesai</label> <label class="form-label">Tanggal Mulai s/d Selesai</label>
<div class="row gutters-xs"> <div class="row gutters-xs">
<div class="col-6"> <div class="col-6">
<input type="text" class="form-control" name="tgl_mulai" data-toggle="datepicker" placeholder="Tanggal Mulai" required autocomplete="off"> <input type="text" class="form-control" name="tgl_mulai" data-toggle="datepicker" placeholder="Tanggal Mulai" required autocomplete="off" value="{{ isset($periode) ? $periode->tgl_mulai : old('tgl_mulai') }}">
</div> </div>
<div class="col-6"> <div class="col-6">
<input type="text" class="form-control" name="tgl_selesai" data-toggle="datepicker" placeholder="Tanggal Selesai" required autocomplete="off"> <input type="text" class="form-control" name="tgl_selesai" data-toggle="datepicker" placeholder="Tanggal Selesai" required autocomplete="off" value="{{ isset($periode) ? $periode->tgl_selesai : old('tgl_selesai') }}">
</div> </div>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="form-label">Status</div> <div class="form-label">Status</div>
<label class="custom-switch"> <label class="custom-switch">
<input type="checkbox" name="is_active" value="1" class="custom-switch-input"> <input type="checkbox" name="is_active" value="1" class="custom-switch-input" {{ isset($periode) ? ($periode->is_active ? 'checked' : '') : '' }}>
<span class="custom-switch-indicator"></span> <span class="custom-switch-indicator"></span>
<span class="custom-switch-description">Aktif</span> <span class="custom-switch-description">Aktif</span>
</label> </label>
@ -63,7 +63,7 @@
$(document).ready(function () { $(document).ready(function () {
$('[data-toggle="datepicker"]').datepicker({ $('[data-toggle="datepicker"]').datepicker({
format: 'yyyy/MM/dd' format: 'yyyy-MM-dd'
}); });
}); });

@ -51,10 +51,12 @@
{{ $item->tgl_selesai }} {{ $item->tgl_selesai }}
</td> </td>
<td> <td>
{{ $item->is_active }} @if($item->is_active)
<span class="tag tag-green">Aktif</span>
@endif
</td> </td>
<td> <td>
<a class="icon" href="javascript:void(0)" title="edit item"> <a class="icon" href="{{ route('periode.edit', $item->id) }}" title="edit item">
<i class="fe fe-edit"></i> <i class="fe fe-edit"></i>
</a> </a>
<a class="icon btn-delete" href="#!" data-id="{{ $item->id }}" title="delete item"> <a class="icon btn-delete" href="#!" data-id="{{ $item->id }}" title="delete item">

@ -31,7 +31,6 @@ Route::middleware(['auth:web'])->group(function(){
Route::get('periode','PeriodeController@index')->name('periode.index'); Route::get('periode','PeriodeController@index')->name('periode.index');
Route::get('tambah-periode','PeriodeController@create')->name('periode.create'); Route::get('tambah-periode','PeriodeController@create')->name('periode.create');
Route::post('tambah-periode', 'PeriodeController@store')->name('periode.store'); 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::get('periode/{periode}/ubah', 'PeriodeController@edit')->name('periode.edit');
Route::post('periode/{periode}/ubah','PeriodeController@update')->name('periode.update'); Route::post('periode/{periode}/ubah','PeriodeController@update')->name('periode.update');
Route::post('periode/{periode}/hapus', 'PeriodeController@destroy')->name('periode.destroy'); Route::post('periode/{periode}/hapus', 'PeriodeController@destroy')->name('periode.destroy');

Loading…
Cancel
Save