我想在我的Laravel项目中使用干预图像库,所以我只是通过Composer安装了它,并将这一行代码添加到config/app.php中。
Intervention\Image\ImageServiceProvider::class,这一行也被添加到aliases部件中:
'Image' => Intervention\Image\Facades\Image::class,现在,在我的控制器上,我编写了以下代码:
class AdminController extends Controller
{
protected function uploadImages($file)
{
$year = Carbon::now()->year;
$imagePath = "/upload/images/{$year}/";
$filename = $file->getClientOriginalName();
$file = $file->move(public_path($imagePath), $filename);
$sizes = ["300","600","900"];
Image::make($file->getRealPath())->resize(300,null,function($constraint){
$constraint->aspectRatio();
})->save(public_path($imagePath . "300_" . $filename));
}
}但是,一旦我填写了我的表单以检查它是否工作,就会弹出以下错误消息:
找不到错误类‘App\Http\Controller\Admin\Image’
这意味着这一行:
Image::make($file->getRealPath())->resize(300,null,function($constraint){那么,当我已经将错误包含在我的项目中时,它为什么会返回这个错误呢?!
如果你知道,请告诉我..。我会很感激的。
谢谢
发布于 2020-11-09 10:40:01
在config/app.php上,您需要添加:
$provides => [
Intervention\Image\ImageServiceProvider::class
],和,
$aliases => [
'Image' => Intervention\Image\Facades\Image::class
]现在,您可以在控制器顶部调用use Image;:
use Image;
class AdminController extends Controller
{
// ...
}https://stackoverflow.com/questions/64749903
复制相似问题