30/09/2018, 23:19
Lỗi update file hình ảnh product trong laravel 5
Hiện tài mình đang học laravel 5 và có bị lỗi phần update hình product và bị lỗi : ErrorException in ProductController.php line 73:
Object of class SymfonyComponentHttpFoundationFileUploadedFile could not be converted to boolean
Đây là code trong ProductController
public function postEdit($id, Request $request){
$product = product::find($id);
$product->name = Request::input('txtName');
$product->alias = changeTitle(Request::input('txtName'));
$product->price = Request::input('txtPrice');
$product->intro = Request::input('txtIntro');
$product->content = Request::input('txtContent');
$product->keywords = Request::input('txtKeywords');
$product->description = Request::input('txtDescription');
$product->user_id = 1;
$product->categories_id = Request::input('sltParent');
// Phần xử lý edit ảnh
$img_current='resources/upload/'.Request::input('img_current');
if(!empty(Request::file('fImages'))){ // đây là dòng báo lỗi
echo "có file";
$file_name=Request::file('fImages')->getClientOriginalName();
$product->image= $file_name;
Request::file('fImages')->move('resources/upload/',$file_name);
if(File::exists($img_current)){
File::delete($img_current);
}
}
else{
echo "Không có file";
}
$product->save();
return redirect()->route('admin.product.list')->with(['flash_level'=>'success','flash_message' => 'Chỉnh sửa sản phẩm thành công']);
}
Bài liên quan