我正在创建一个员工休假表单,其中有3个类别的权限来自另一个表,即:“特兰巴特”、“普朗塞帕“、“萨基特”. select option for categories
对于“SAKIT”类别,数据已成功保存到数据库,因为没有要填写的jam_mulai和jam_selesai。form for category "SAKIT"
对于“Terlambat”,“Pulang Cepat“类别,如果选中,jam_mulai和jam_selesai表单以及我在控制器中创建的jml_jam字段也会出现。但是,当提交时,I DD($IZIN)的数据不会出现,而是返回到index.blade.php页面。form for "TERLAMBAT" and "PULANG CEPAT"
这是在检查时网络侧的响应:previewheader in network打印机
这是表单模式添加数据权限的代码:
enter code here {{-- FORM PENGAJUAN IZIN--}}
{{-- bbootsrapt clockpicker --}}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/clockpicker/0.0.7/bootstrap-clockpicker.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/clockpicker/0.0.7/bootstrap-clockpicker.min.js"></script>
<div class="modal fade" id="smallModal" tabindex="-1" role="dialog" aria-labelledby="smallModal" aria-hidden="true">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Form Permohonan Izin</h4>
</div>
<div class="modal-body">
<form class="input" action="{{ route('izinstore')}}" method="POST" enctype="multipart/form-data">
@csrf
@method('POST')
<div class="form-group">
<label for="id_karyawan" class="col-form-label">Nama</label>
<input type="text" class="form-control" id="id_karyawan" value="{{Auth::user()->name}}" readonly>
<input type="hidden" class="form-control" name="id_karyawan" id="id_karyawan" value="{{$karyawan}}" hidden>
</div>
<div class="form-group col-sm" id="jenisizin">
<label for="id_jenisizin" class="col-form-label">Kategori Izin</label>
<select name="id_jenisizin" id="id_jenisizin" class="form-control">
<option>-- Pilih Kategori --</option>
@foreach ($jenisizin as $data)
<option value="{{ $data->id}}"
{{ old('id_jenisizin') == $data->id ? 'selected' : '' }}
>{{ $data->jenis_izin }}
</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="keperluan" class="col-form-label">Keperluan</label>
<input type="text" class="form-control" name="keperluan" id="keperluan" required>
</div>
<div class="row">
<div class="col-sm-6">
<div class="">
{{-- <form class="" action="#"> --}}
<div class="form-group">
<label for="tgl_mulai" class="form-label">Tanggal Mulai</label>
<div class="input-group">
<input type="text" class="form-control" placeholder="mm/dd/yyyy" id="datepicker-autoclose3" name="tgl_mulai" onchange=(jumlahhari()) autocomplete="off" required>
<span class="input-group-addon bg-custom b-0"><i class="mdi mdi-calendar text-white"></i></span>
</div>
</div>
{{-- </form> --}}
</div>
</div>
<div class="col-sm-6">
<div class="">
{{-- <form class="" action="#"> --}}
<div class="form-group">
<label for="tgl_selesai" class="form-label">Tanggal Selesai</label>
<div class="input-group">
<input type="text" class="form-control" placeholder="mm/dd/yyyy" id="datepicker-autoclose4" name="tgl_selesai" onchange=(jumlahhari()) autocomplete="off" required>
<span class="input-group-addon bg-custom b-0"><i class="mdi mdi-calendar text-white"></i></span>
</div>
</div>
{{-- </form> --}}
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6" id="jmulai">
<div class="">
<label for="jam_mulai">Dari Jam</label>
<div class="input-group clockpicker pull-center" data-placement="top" data-align="top" autocomplete="off" data-autoclose="true">
<input type="text" class="form-control" name="jam_mulai" id="mulai" value="{{ old('jam_mulai') }}">
<span class="input-group-addon">
<span class="fa fa-clock-o"></span>
</span>
</div>
</div>
</div>
<div class="col-lg-6" id="jselesai">
<div class="">
<label for="jam_selesai">Sampai Jam</label>
<div class="input-group clockpicker pull-center" data-placement="top" data-align="top" autocomplete="off" data-autoclose="true">
<input type="text" class="form-control" name="jam_selesai" id="selesai" value="{{ old('jam_selesai') }}">
<span class="input-group-addon">
<span class="fa fa-clock-o"></span>
</span>
</div>
</div>
</div>
</div>
<div class="form-group col-sm" id="jumlahhari">
<label for="jml_hari" class="col-form-label">Jumlah Hari</label>
<input type="text" class="form-control" name="jml_hari" id="jml" readonly>
</div>
<div class="form-group col-sm" id="jumlahjam">
{{-- <label for="jml_jam" class="col-form-label">Jumlah Jam</label> --}}
<input type="hidden" class="form-control" name="jml_jam" value="{{old('jml_jam')}}" id="jam">
</div>
<div class="form-group col-sm">
<input type="hidden" class="form-control" name="status" id="status" value="Pending" hidden>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-success" value="save">Send</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
//show clockpicker
jQuery(function(j){
j('.clockpicker').clockpicker()
.find('input').change(function()
{
console.log(this.value);
});
var input = j('#single-input').clockpicker({
placement: 'bottom',
align: 'left',
autoclose: true,
'default': 'now'
});
});
//show/hide clockpicker when id_jenisizin selected
$(function()
{
$('#jmulai').prop("hidden", true);
$('#jselesai').prop("hidden", true);
// $('#jumlahjam').prop("hidden", true);
$('#jumlahhari').prop("hidden", true);
$('#jenisizin').on('change', function(e)
{
if(e.target.value== 1 || e.target.value== 2)
{
$('#jmulai').prop("hidden", false);
$('#jselesai').prop("hidden", false);
// $('#jumlahjam').prop("hidden", false);
$('#jumlahhari').prop("hidden", false);
//selisih waktu jika terlambat
if(e.target.value== 1)
{
//set nilai jam_mulai
$('#mulai').val('08:00');
$('#mulai').attr('readonly', false);
$('#mulai').css('background-color' , '#DEDEDE');
}else {
//set nilai jam_selesai
$('#selesai').val('17:00');
$('#selesai').attr('readonly', false);
$('#selesai').css('background-color' , '#DEDEDE');
}
// alert('DATA ADA');
} else {
$('#jmulai').prop("hidden", true);
$('#jselesai').prop("hidden", true);
// $('#jumlahjam').prop("hidden", true);
$('#jumlahhari').prop("hidden", false);
}
// alert('id:' + e.target.value);
});
});
// =========================================================
//datepicker for tgl_mulai & tgl_selesai
$('#datepicker-autoclose3').datepicker({
autoclose: true,
});
$('#datepicker-autoclose4').datepicker({
autoclose: true,
});
function jumlahhari(){
var start= $('#datepicker-autoclose3').val();
var end = $('#datepicker-autoclose4').val();
var start_date= new Date(start);
var end_date = new Date(end) ;
var daysOfYear= [];
//mendapatkan jumlah hari izin jika sakit
for (var d = start_date; d <= end_date; d.setDate(d.getDate() + 1)){
//cek workdays
let tgl = new Date(d);
if(tgl.getDay() !=0 && tgl.getDay() !=6){
daysOfYear.push(tgl);
console.log(tgl);
} else{
console.log("hari Libur" + tgl.getDay());
};
};
//mengambil value tanggal mulai
$('#start_date').on('change', function(){
jumlahhari();
});
//mengambil value tanggal selesai
$('#end_date').on('change', function(){
jumlahhari();
});
console.info(daysOfYear);
$('#jml').val(daysOfYear.length ?? 0);
};
</script>
<!-- jQuery -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/modernizr.min.js"></script>
<script src="assets/js/detect.js"></script>
<script src="assets/js/fastclick.js"></script>
<script src="assets/js/jquery.slimscroll.js"></script>
<script src="assets/js/jquery.blockUI.js"></script>
<script src="assets/js/waves.js"></script>
<script src="assets/js/wow.min.js"></script>
<script src="assets/js/jquery.nicescroll.js"></script>
<script src="assets/js/jquery.scrollTo.min.js"></script>
{{-- plugin js --}}
<script src="assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
{{-- // Datatable init js --}}
<script src="assets/pages/datatables.init.js"></script>
<script src="assets/js/app.js"></script>
{{-- // Plugins Init js --}}
<script src="assets/pages/form-advanced.js"></script>
这是CONTROLLER中的代码存储数据:
public function store(Request $request)
{
$karyawan = Auth::user()->karyawans->id;
// dd($request->id_jenisizin);
if($request->has('jam_mulai') && $request->has('jam_selesai'))
{
if($request->id_jenisizin == 1 || $request->id_jenisizin == 2)
{
// dd($request->all());
$validate = $request->validate([
'id_karyawan' => 'required',
'id_jenisizin' => 'required',
'keperluan' => 'required',
'tgl_mulai' => 'required',
'tgl_selesai' => 'required',
'jam_mulai' => 'required',
'jam_selesai' => 'required',
'jml_hari' => 'required',
'jml_jam' => 'required',
'status' => 'required',
]);
// dd($validate);
$izin = New Izin;
$izin->id_karyawan = $karyawan;
$izin->id_jenisizin= $request->id_jenisizin;
$izin->keperluan = $request->keperluan;
$izin->tgl_mulai = Carbon::now()->format("Y-m-d");
$izin->tgl_selesai = Carbon::now()->format("Y-m-d");
$izin->jam_mulai = $request->jam_mulai;
$izin->jam_selesai = $request->jam_selesai;
$izin->jml_hari = $request->jml_hari;
$jammulai = Carbon::parse($request->jam_mulai);
$jamselesai= Carbon::parse($request->jam_selesai);
$time_range= $jamselesai->diff($jammulai)->format("%H:%I");
$izin->jml_jam = $time_range;
$izin->status = 'Pending';
$izin->save();
dd($izin);
return redirect()->back()->withInput();
}else{
// dd($request->all());
$validate = $request->validate([
'id_karyawan' => 'required',
'id_jenisizin' => 'required',
'keperluan' => 'required',
'tgl_mulai' => 'required',
'tgl_selesai' => 'required',
'jml_hari' => 'required',
'status' => 'required',
]);
// dd($validate);
$izin = New Izin;
$izin->id_karyawan = $karyawan;
$izin->id_jenisizin= $request->id_jenisizin;
$izin->keperluan = $request->keperluan;
$izin->tgl_mulai = Carbon::now()->format("Y-m-d");
$izin->tgl_selesai = Carbon::now()->format("Y-m-d");
$izin->jml_hari = $request->jml_hari;
$izin->status = 'Pending';
$izin->save();
// dd($izin);
return redirect()->back()->withInput();
};
}
}
这是laragon数据库中的PERMISSION表:table IZIN in database
2条答案
按热度按时间bweufnob1#
您可以尝试在刀片文件中打印错误,因为下面代码可能会对您有所帮助。
控制器代码
在刀片文件中
jv4diomz2#
首先删除重复的逻辑,例如:
然后在视图(
.blade.php
文件)的某个位置显示Validation-errors,例如: