laravel 使用干预时找不到图像类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37455810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Image class not found when using Intervention
提问by Joe W
I have installed Laravel 5.2 and Intervention, this is now in the composer.json file in the project.
我已经安装了 Laravel 5.2 和 Intervention,它现在在项目的 composer.json 文件中。
"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.
阅读教程后,它提到了一个 Image.php 文件,一旦您安装了 Intervention,该文件应该位于项目内的 config 文件夹中。我相信我已经正确安装了干预,但是当我尝试使用干预功能时,它不起作用。
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 语句
use Intervention\Image\Facades\Image as Image;
回答by Abhishek
In your app.php Add this in your aliases
:
在你的 app.php 中添加这个aliases
:
'Image' => Intervention\Image\Facades\Image::class,
and in your providers
并且在你的 providers
Intervention\Image\ImageServiceProvider::class,
Don't forget to do php artisan config:cache
after this.
别忘了php artisan config:cache
做完这件事。
回答by Cevin Ways
First, you can use composer :
首先,您可以使用 composer :
composer require intervention/image
Then declare it on app.php :
然后在 app.php 上声明:
'providers' => [
// ...
Intervention\Image\ImageServiceProvider::class,
]
Then, still on app.php on 'aliases' declare it :
然后,仍然在 app.php 上的“别名”上声明它:
'aliases' => [
// ...
'Image' => Intervention\Image\Facades\Image::class,
]
Hope it will help
希望它会有所帮助
回答by henrik
If you've followed the tutorial here: http://image.intervention.io/getting_started/installation#laravelAnd 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.
如果你已经在这里跟着教程:http://image.intervention.io/getting_started/installation#laravel并按照上述方法做了一切,最后生成所有的新类与作曲家命令:composer dump-autoload
。这将自动加载您的新外观。在此之后,您可以简单地use Image;
在您希望在其中使用外观的类中导入图像外观。