I am learning Laravel 8 and came across this problem. So, I made a controller class with FacadesDB Insert function. This is my code :
public function aksimenulis_laporan(Request $request){
$filefoto = $request->foto;
DB::table('pengaduan')->insert([
'tgl_pengaduan' => date('Y-m-d'),
'nik' => $_POST['nik'],
'isi_laporan' => $_POST['isi_laporan'],
'foto' => $filefoto->getClientOriginalName(),
'status' => '0',
]);
// isi dengan nama folder tempat kemana file diupload
$tujuan_upload = storage_path();
// upload file
$filefoto->move($tujuan_upload,$filefoto->getClientOriginalName());
return redirect('');
}
https://i.stack.imgur.com/VTJyS.png This is my database table structure.
And I am trying to insert 'foto' with value of 'id_pengaduan' or the primary key, like using this code. Which will be PrimaryKey_OriginalFileName
'foto' => $filefoto-> 'id_pengaduan'.'_'.getClientOriginalName(),
But the problem I didn't have the value yet. Is there a way that I can value 'foto' with the primary key of the table?