文章5:介入图像,imagecache.缺少参数2错误


Laravel 5: Intervention Image, imagecache. Missing argument 2 error

尝试使用干预图像来调整图像大小。那部分正常工作了。现在我想缓存图像10分钟,但是当我上传一篇带有图像的新文章时,我得到了这个堆栈跟踪:

ArticlesController.php第150行错误:缺少参数2为App ' Http '控制器' ArticlesController: App ' Http '控制器关闭{}(),在/home/vagrant/Sites/vision/vendor/intervention/图像/src/干预/图像/ImageManager.php在第85行定义了

这就是魔术发生的地方,在ArticlesController.php:

private function createArticle(ArticleRequest $request)
{
    $article = Auth::user()->articles()->create($request->all());
    $this->syncTags($article, $request->input('tag_list'));
    $image = $request->file('image');
    $directory = 'img/articles/';
    $path = $image->getClientOriginalName();
    $image->move($directory, $path);
    Image::create([
        'path' => $path,
        'article_id' => $article->id
    ]);
    // This one resizes the image successfully.
    ImgResizer::make($directory . $path)->fit(600, 360)->save($directory . $path);
    // This one is supposed to resize and cache the image, but spits the error above.
    ImgResizer::cache(function($image, $directory, $path) {
        $image->make($directory . $path)->fit(600, 360)->save($directory . $path);
    }, 10);
}

别担心,我不会同时使用两个语句。只是展示一下我在这两方面都做了些什么,希望有人能把我引向正确的方向,告诉我哪里做错了,因为我看不出来。

问题似乎与您的闭包函数有关。根据缓存对象的文档,它只向闭包传递1个参数。你需要3个参数

function($image, $directory, $path)

因此,"缺少参数2…对于闭包"错误。您需要修改闭包以支持传递的一个参数。