调用未定义的方法Intervention \ Image \ ImageManager :: upload()

时间:2018-02-15 11:09:56

标签: php laravel

我正在尝试将图像上传到我的数据库中。当我上传时,我收到以下错误

  
    

调用未定义的方法Intervention \ Image \ ImageManager :: upload()

  

在互联网上搜索解决方案,我发现了这种方法

添加此行'Intervention\Image\ImageServiceProvider' in my $providers in config/app.php 添加此行'Image' => 'Intervention\Image\Facades\Image' in my $aliases in config/app.php

在我的控制器中,我也使用了Image。但是我仍然在上面得到这个错误。我能错过什么?

控制器

public function uploadImagePost(UploadUserImageRequest $request)
    {

        $user = Auth::user();

        $image = $request->file('profile_image');

        if (false === empty($user->image_path)) {
            $user->image_path->destroy();
        }

        $relativePath = 'uploads/users/' . $user->id;
        $path = $relativePath;


        $dbPath = $relativePath . DIRECTORY_SEPARATOR . $image->getClientOriginalName();

        $this->directory(public_path($relativePath));

        Img::upload($image, $path);

        $user->update(['image_path' => $dbPath]);

        return redirect()->route('my-account.home')
            ->with('notificationText', 'User Profile Image Uploaded successfully!!');
    }

1 个答案:

答案 0 :(得分:2)

您使用过的图书馆没有upload()方法。使用save()方法保存文件。

// read image from temporary file
$img = Image::make($_FILES['image']['tmp_name']);

// save image
$img->save('foo/bar.jpg');

参考this link for more details