【问题标题】:Class image not found when using intervention使用干预时找不到类图像
【发布时间】:2016-04-21 10:30:53
【问题描述】:

我正在使用 Laravel 和 Intervention 来处理来自用户的文件上传,我已经使用 Composer 安装了 Intervention,但是当我尝试使用它的一些功能时,我收到此错误消息 Class 'Intervention\Image\Facades\Image' not found 我检查了我的 app.php 文件我已经向别名和提供程序添加了正确的代码行,但现在我不确定是什么问题

这是我的功能

public function postAvatarUpload(Request $request)
    {
         $this->validate($request, [
            'image' => 'required|image|max:3000|mimes:jpeg,jpg,png',
        ]);
        $user = Auth::user();

        $usersname = $user->username;
       $file = $request->file('image');
       // $ext = $file->getClientOriginalExtension();
        $ext= Input::file('image')->getClientOriginalExtension();
        $filename = $usersname . '.' . $ext;
        if (Storage::disk('public')->has($usersname)) {
            Storage::delete($usersname);
        }
           Storage::disk('public')->put($filename, File::get($file));

           $path = public_path('app/public/'. $filename);
            Auth::user()->update([
                'image' => $path,
            ]);
        $resizedImg = Image::make($path)->resize(200,200);
       // $ext = $file->getClientOriginalExtension();

        return redirect()->route('profile.index', 
                ['username' => Auth::user()->username]);
    }

【问题讨论】:

    标签: laravel laravel-5.2 intervention


    【解决方案1】:

    您还需要在文件顶部、命名空间之后导入它。既然你说你已经设置了门面,那么你需要做的就是:

    use Image;
    

    【讨论】:

    • 我正在使用 Intervention\Image\Facades\Image;刚试了你说的,我找不到类“图像”
    • 这是一个非常愚蠢的问题,但必须问一下——你确定这个包确实已经安装了,而且 Composer 不只是更新了 composer.json 文件吗?
    【解决方案2】:

    按照documentation 中的说明添加外观和提供程序。然后运行composer dumpauto -o 命令。

    然后将use Image 添加到您的班级,或像这样使用它:

    $resizedImg = \Image::make($path)->resize(200,200);
    

    【讨论】:

    • 我已经这样做了,但仍然没有从文档中看到的唯一内容是我的配置文件夹中没有 image.php 文件,但我使用的是 Laravel 5.2
    • 从文档中尝试这个命令:php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5" - 这个命令应该将配置文件复制到config 文件夹。
    • 谢谢我已经这样做了,但是我没有得到任何标签 [] 的回报
    猜你喜欢
    • 2015-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-09
    • 2020-04-29
    • 2015-03-12
    • 2020-03-19
    • 1970-01-01
    相关资源
    最近更新 更多