我是Laravel的新手,我的方法商店就像这样有问题。
这是我控制器中的方法。
public function store(Request $request)
{
if($request->ajax()){
$data = array(
'karyawan_id'=>$request->id_kar,//here it is the problem
'tgl_berlaku'=>$request->tgl_berlaku,
'jumlah_gapok'=>$request->jumlah_gapok,
'created_by'=>auth()->user()->id,
'data_sekolah_id' => Library::sekolahSelected(),
);
$this->save("tb_gaji_pokok",$data);
if($data){
$response = $this->returnSuccess('', trans('messages.success.add'));
return response()->json($response);
}else{
$response = $this->returnData('', trans('messages.error.add'));
return response()->json($response);
}
}
}
这是我的ajax,它在视图中创建模态。
function atur(id,a){
var kar_id ='<div class="col-sm-9"><input
type="text" class="form-control" id="id_kar"
name="id_kar" disabled> <input type="hidden"
class="form-control" name="id" value="{{ $id }}">
</div>';
var input_gaji = '<div class="form-group"><label
class="col-sm-3 control-label">Atur Gaji
Pokok</label><div class="col-sm-6"><input
type="text" id="jumlah_gapok" class="form-control"
name="jumlah_gapok" placeholder="Jumlah"></div>
</div>';
var tanggal = '<div class="form-group"><label
class="col-sm-3 control-label">Tanggal
Berlaku</label><div class="col-sm-6"><div
class="input-group"><input type="text"
id="tgl_berlaku" class="form-control tgl_berlaku"
name="tgl_berlaku" placeholder="Tanggal Berlaku">
<span class="input-group-addon"><i class="fa fa-
calendar"></i></span></div></div></div>';
var infoModal = $('#gajipokok');
if(id) {
$.ajax({
url: path+'/aturgaji/'+id+'/'+a,
type: "GET",
dataType: "json",
success:function(data) {
alert(data.karyawan.nama);
htmlData = '<h4>Nama karyawan :
'+data.karyawan.nama+'</h4><h4>Status :
'+data.karyawan.status_karyawan+'</h4><h4>Jabatan :
'+data.jabatan.nama_jabatan+'</h4>
<td>'+input_gaji+'</td><td>'+tanggal+'</td>'+kar_id;
infoModal.find('.modal-body').html(htmlData);
$('.tgl_berlaku').datepicker({
format: "yyyy-mm-dd",
todayBtn: "linked",
autoclose: true,
todayHighlight: true,
}).on('changeDate', function(e) {
$('#form').formValidation('revalidateField',
'tgl_berlaku');
});//datepicker tgl_awal
$('#id_kar').val(data.karyawan.id);
modalGajiShow();
}
);
}
else {
modalGajiHide();
notify(0, 'Something when wrong');
}
}
问题在于:
'karyawan_id'=>$request->id_kar,
该请求什么都不返回,所以在数据库中,karyawan_id的列仍然是空的
有人可以帮我解决这个问题吗?谢谢。