I try to check if the record is not exist then i will do the insert, but it's not working.This is my code:
//check if nomor permohonan is exist
$data_pemohon = DB::table('data_pemohon')->select('*')->where('noper', $noper)->get();
if(is_null($data_pemohon)){
return response(null);
}else{
$data_antrian = DB::table('antrian_sp')->select('*')->where('noper', $noper)->first();
if(is_null($data_antrian)){
$nama = DB::table('data_pemohon')->select('nama')->where('noper', $noper)->first();
$status = DB::table('data_pemohon')->select('status_paspor')->where('noper', $noper)->first();
$data = array('tanggal'=>$tanggal, 'jam'=>$jam, 'noper'=>$noper, 'nama'=>$nama->nama, 'status'=>$status->status_paspor);
$add_antrian= DB::table('antrian_sp')->insert($data);
if($add_antrian){
return response($data_pemohon);
}else{
echo "error";
}
}else{
return response(1);
}
}