the cover overwrited by this line
$buku->cover_buku = $validatedData['cover_buku'];
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
this is my first time using laravel. i want to save the image that i have uploaded and display the filename of the image in database table and show the thumbnail of my uploaded image in my web page. however, when I try to upload the image, it is saved in the database but it only shows the location where the uploaded file is stored as .tmp in xampp.
but the image that I uploaded is with the file name that matches what I want in the folder 'public/uploads/books/' but why does it become C:\xampp\tmp\php5373.tmp file in the database? help me pls
here is my controller
public function store (BukuFormRequest $request){
$validatedData = $request->validated();
$buku = new Buku;
$buku->id_buku= $validatedData['id_buku'];
if($request->hasFile('cover_buku')){
$file = $request->file('cover_buku');
$ext = $file->getClientOriginalExtension();
$filename = time().'.'.$ext;
$file->move('uploads/buku/', $filename);
$buku->cover_buku = $filename;
}
$buku->cover_buku = $validatedData['cover_buku'];
$buku->judul_buku = $validatedData['judul_buku'];
$buku->nama_penulis = $validatedData['nama_penulis'];
$buku->tgl_terbit = $validatedData['tgl_terbit'];
$buku->halaman = $validatedData['halaman'];
$buku->ukuran = $validatedData['ukuran'];
$buku->isbn = $validatedData['isbn'];
$buku->keterangan_buku = $validatedData['keterangan_buku'];
$buku->slug = Str::slug($validatedData['slug']);
$buku->status_buku = $request->status_buku == true ? '1' : '0';
$buku->save();
return redirect('admin/buku') -> with('message', 'Data Buku Berhasil Ditambahkan!');
}
here is the rules
public function rules()
{
'cover_buku' => [
'nullable',
'image',
'mimes:jpg,jpeg,png',
'max:5120'
]
the cover overwrited by this line
$buku->cover_buku = $validatedData['cover_buku'];
Please or to participate in this conversation.