Im new in Laravel, and I have problem in my method store like this.
this is my method in my controller.
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);
}
}
}
and this is my ajax which is create the modal in view.
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="">
</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');
}
}
and the problem is here :
'karyawan_id'=>$request->id_kar,
that request return nothing, so in the database, karyawan_id's column still Null
can someone help me fix this? thank you.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2fl3TRs
via IFTTT
Aucun commentaire:
Enregistrer un commentaire