Laravel 5.4和干预图像调用未定义的方法Illuminate \ Database \ Query \ Builder :: image()

时间:2017-03-24 15:00:01

标签: php laravel

我正在使用干预图像(http://image.intervention.io/)包并使用其Laravel集成。如文档中所述,我已将以下内容添加到服务提供商:

Intervention\Image\ImageServiceProvider::class

并将以下别名添加到外墙

'Image' => Intervention\Image\Facades\Image::class

在我的控制器中,我正如文档所述:

    // Create a thumbnail for the image
    $thumb = Image::make('images/' . $date . "/" . $request->file->hashName());
    $thumb->resize(320, 240);
    $thumb->save('images/' . $date . "/thumb_" . $request->file->hashName());

但是我收到了这个错误:

ErrorException: Call to undefined method Illuminate\Database\Query\Builder::image() 

编辑:

类名中可能存在冲突吗?我还有一个名为Image的模型,所以我认为它可能与那个

有关
    // Save the image details to the database
    $image = new Image;
    $image->filename = $request->file->hashName();
    $image->path = 'images/' . $date;
    $image->album_id = $request->id;
    $image->save();

    // Create a thumbnail for the image
    $thumb = Image::make('images/' . $date . "/" . $request->file->hashName());
    $thumb->resize(320, 240);
    $thumb->save('images/' . $date . "/thumb_" . $request->file->hashName());

1 个答案:

答案 0 :(得分:3)

是的,这是一个类名冲突。你可以用这个:

$thumb = \Intervention\Image\Facades\Image::make('images/' . $date . "/" . $request->file->hashName());

并删除代码中的use Image;use Intervention\Image\Facades\Image;