I have two tables, a question table and a theme table, in the theme table there is a theme name and division name column. when I import data in the question table I enter the name of the theme, and when I enter the name of the theme I want to automatically enter the name of the division into the input.
these are just a few scripts that I can make, first I take the name of the theme and if the name of the imported theme isn't in the theme table then a notification will appear. and furthermore I don't know how I should make the script.
$namatema = $key->tema_soal;
$cek_temasoal = DB::table('temasoal')->where('namatema',$namatema)->first();
if ($cek_temasoal!=null) {
$id_temasoal = $cek_temasoal->id;
} else {
$new_tema['namatema'] = $namatema;
$new_tema['id_divisi'] = $id_divisi;
$new_tema['standartlulus'] =0 ;
return redirect()->back()->with(
['message'=>'Data Gagal di Import!, Kemungkinan Anda Memasukan Tema Soal Baru, Perbarui Dahulu Data Tema Soal Anda!','message_type'=>'warning']);
// $id_temasoal = DB::table('temasoal')->insertGetId($new_tema);
}
// if(!empty($key->id_divisi)) {
$insert = [
'id_divisi' => $id_divisi,
'id_temasoal' => $id_temasoal,
'pertanyaan' => $key->pertanyaan,
'plhna' => $key->plhna,
'plhnb' => $key->plhnb,
'plhnc' => $key->plhnc,
'plhnd' => $key->plhnd,
'plhne' => $key->plhne,
'kunci' => $key->kunci,
'status' => ''
// 'created_at' => date('Y-m-d H:i:s')
];
$result = DB::table('soal')->insert($insert);
so how do I when I import data and enter the name of the theme automatically the division name will enter the database.this is a picture of my question table
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/34Jo1lG
via IFTTT
Aucun commentaire:
Enregistrer un commentaire