Я пытаюсь проверить, не существует ли запись, тогда я сделаю вставку, но она не работает. Это мой код:
//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);
}
}
$data_antrian
может иметь дубликаты в качестве кода, выполняемого одновременно, вы можете использоватьnoper
в качестве первичного ключа, чтобы гарантировать, что будет создан только один. Кроме того, мне любопытно с$data_pemohon
, так как->get()
вернет пустую коллекцию вместо нуля, если она не дала результата cmiiw. - person Bagus Tesa   schedule 18.08.2018