3 回答

TA貢獻1798條經驗 獲得超7個贊
試試這個它可以幫助你..
$post_data = $request->except('imagefile');
$imagefile = $request->file('imagefile');
$temp_path = $imagefile->store('public/temp');
$filename = $request->file('image');
$post_data->imagefile = $filename;
$a = new Test;
$a->fill($post_data)->save();
或者
$a = new Test;
$a->imagefile = $filename; // here imagefile equal to your db fild
$a->save();

TA貢獻1852條經驗 獲得超7個贊
您需要在保存之前將文件名分配給值數組。也不要使用$request->all();這個包含圖像對象&我們在保存時不需要它。我們只需要文件名。在下面的代碼中,我在保存之前將文件名分配到 $post_data 數組中。
$post_data = $request->except('imagefile');
$imagefile = $request->file('imagefile');
$temp_path = $imagefile->store('public/temp');
$filename = $request->file('image')->hashName();
$post_data->imagefile = $filename;
$a = new Test;
$a->fill($post_data)->save();
- 3 回答
- 0 關注
- 113 瀏覽
添加回答
舉報