Laravel 5:干预图像,图像缓存。缺少参数 2 错误
Laravel 5: Intervention Image, imagecache. Missing argument 2 error
正在尝试使用干预图像调整图像大小。让那部分工作。现在我想将图像缓存 10 分钟,但是当我上传带有图像的新文章时,我得到了这个堆栈跟踪:
ErrorException in ArticlesController.php line 150: Missing argument 2
for
App\Http\Controllers\ArticlesController::App\Http\Controllers{closure}(),
called in
/home/vagrant/Sites/vision/vendor/intervention/image/src/Intervention/Image/ImageManager.php
on line 85 and defined
这就是奇迹发生的地方,在 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);
}
别担心,我不会同时使用这两种语句。只是展示我在这两个方面所做的事情,希望有人可以引导我朝着正确的方向前进,并告诉我我做错了什么,因为我看不到它。
问题似乎与您的闭包函数有关。根据缓存对象上的 docs,它只将 1 个参数传递给闭包。您要求 3 个参数。
function($image, $directory, $path)
因此,"missing argument 2 ... for closure" 错误。您将需要修改闭包以支持传递的一个参数。
正在尝试使用干预图像调整图像大小。让那部分工作。现在我想将图像缓存 10 分钟,但是当我上传带有图像的新文章时,我得到了这个堆栈跟踪:
ErrorException in ArticlesController.php line 150: Missing argument 2 for App\Http\Controllers\ArticlesController::App\Http\Controllers{closure}(), called in /home/vagrant/Sites/vision/vendor/intervention/image/src/Intervention/Image/ImageManager.php on line 85 and defined
这就是奇迹发生的地方,在 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);
}
别担心,我不会同时使用这两种语句。只是展示我在这两个方面所做的事情,希望有人可以引导我朝着正确的方向前进,并告诉我我做错了什么,因为我看不到它。
问题似乎与您的闭包函数有关。根据缓存对象上的 docs,它只将 1 个参数传递给闭包。您要求 3 个参数。
function($image, $directory, $path)
因此,"missing argument 2 ... for closure" 错误。您将需要修改闭包以支持传递的一个参数。