错误更新图片产品laravel 5

时间:2016-08-22 08:34:11

标签: laravel-5

ProductController.php第73行中的ErrorException: Symfony \ Component \ HttpFoundation \ File \ UploadedFile类的对象无法转换为布尔值

我的代码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'))){ // line error
        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']);
}

我的错误 enter image description here

1 个答案:

答案 0 :(得分:0)

尝试将检查更改为

if($request->hasFile('fImages') && $request->file('fImages')->isValid()) {
   ...
}