0
votes

Trying to using Intervention Image to resize images. Got that part working. Now I want to cache the images for 10 minutes, but I am getting this stack trace when I upload a new article with an image:

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

This is where the magic is happening, in 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);
}

Don't worry, I'm not using both statements at once. Just showing what I am doing in both and hopefully someone can lead me in the right direction and show me what I'm doing wrong, because I don't see it.

1
150 is the second ImgResizer - Lansana Camara
Was trying to find the documentation, but the ImgResizer class does not exist from what I can tell... - Chris
It's actually Image.. I just did "Intervention\Image\Facades\Image as ImgResizer;" because I am already using Image for my image model. - Lansana Camara

1 Answers

1
votes

The issue appears to be with your closure function. According to the docs on the cache object, it only passes 1 argument to the closure. You are asking for 3 arguments.

function($image, $directory, $path)

Hence, the "missing argument 2 ... for closure" error. You're going to need to modify your closure to support the one argument passed.