我已经安装了Laravel 5.2和Intervention,现在它在项目的composer.json文件中。
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"intervention/image": "^2.3"
},
阅读完教程后,它会提到一个Image.php文件,一旦安装了Intervention,它应该位于项目内的config文件夹中。我相信我已经正确安装了干预,但是当我尝试使用干预功能时,它不起作用。
当我尝试使用这行代码时,我得到了这个错误
$resizedImg = Image::make($path)->resize(200,200);
C:\xampp\htdocs\socialNet\vendor\laravel\framework\src\Illuminate\Container\Container.php line 738:
类图像不存在
在我使用此函数的文件中,我包含此Use语句
use Intervention\Image\Facades\Image as Image;
在你的app.php中添加这个在你的aliases
中:
'Image' => Intervention\Image\Facades\Image::class,
在你的providers
Intervention\Image\ImageServiceProvider::class,
在此之后不要忘记做php artisan config:cache
。
首先,你可以使用composer:
composer require intervention/image
然后在app.php上声明它:
'providers' => [
// ...
Intervention\Image\ImageServiceProvider::class,
]
然后,仍然在app.php上'别名'声明它:
'aliases' => [
// ...
'Image' => Intervention\Image\Facades\Image::class,
]
希望它会有所帮助
如果你已经按照这里的教程:http://image.intervention.io/getting_started/installation#laravel并按照描述完成所有操作,最后使用composer命令生成所有新类:composer dump-autoload
。这将自动加载您的新外观。在此之后,您可以在要使用外观的类中通过use Image;
导入Image外观。