Image class not found when using Intervention

流过昼夜 提交于 2021-01-28 19:33:10

问题


I have installed Laravel 5.2 and Intervention, this is now in the composer.json file in the project.

"require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*",
        "intervention/image": "^2.3"
    },

After reading tutorials, it mentions an Image.php file that should be in the config folder inside the project once you have installed Intervention. I believe I have installed Intervention correctly but when I try to use the Intervention functions it does not work.

When I try to use this line of code I get this error

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

C:\xampp\htdocs\socialNet\vendor\laravel\framework\src\Illuminate\Container\Container.php line 738:

Class image does not exist

and in the file I am using this function I include this Use statement

use Intervention\Image\Facades\Image as Image;

回答1:


In your app.php Add this in your aliases:

'Image' => Intervention\Image\Facades\Image::class,

and in your providers

Intervention\Image\ImageServiceProvider::class,

Don't forget to do php artisan config:cache after this.




回答2:


First, you can use composer :

composer require intervention/image

Then declare it on app.php :

'providers' => [
    // ...
    Intervention\Image\ImageServiceProvider::class,
]

Then, still on app.php on 'aliases' declare it :

'aliases' => [
    // ...
    'Image' => Intervention\Image\Facades\Image::class,
]

Hope it will help




回答3:


If you've followed the tutorial here: http://image.intervention.io/getting_started/installation#laravel And done everything as described, finally generate all the new classes with the composer command: composer dump-autoload. This will autoload your new facade. After this you can import the Image facade simply by use Image; in the class you wish to use the facade in.



来源:https://stackoverflow.com/questions/37455810/image-class-not-found-when-using-intervention

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!