【问题标题】:Laravel 5: Intervention Image, imagecache. Missing argument 2 errorLaravel 5:干预图像,图像缓存。缺少参数 2 错误
【发布时间】:2016-01-26 09:01:28
【问题描述】:

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

ArticlesController.php 第 150 行中的 ErrorException:缺少参数 2 为了 App\Http\Controllers\ArticlesController::App\Http\Controllers{closure}(), 叫进来 /home/vagrant/Sites/vision/vendor/intervention/image/src/Intervention/Image/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);
}

别担心,我不会同时使用这两个语句。只是展示我在这两个方面都在做什么,希望有人可以引导我朝着正确的方向前进,并告诉我我做错了什么,因为我没有看到它。

【问题讨论】:

  • 150 是第二个 ImgResizer
  • 正在尝试查找文档,但据我所知,ImgResizer 类不存在...
  • 实际上是 Image.. 我刚刚做了“Intervention\Image\Facades\Image as ImgResizer;”因为我已经在使用 Image 作为我的图像模型。

标签: php laravel laravel-5 intervention


【解决方案1】:

问题似乎与您的闭包函数有关。根据缓存对象上的docs,它只将1个参数传递给闭包。您要求 3 个参数。

function($image, $directory, $path)

因此,“缺少参数 2 ... 用于关闭” 错误。您将需要修改您的闭包以支持传递的一个参数。

【讨论】:

    猜你喜欢
    • 2016-01-11
    • 2015-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-11
    • 1970-01-01
    • 1970-01-01
    • 2017-08-03
    相关资源
    最近更新 更多