问题描述
我想为我的Laravel项目使用Intervention Image库,所以我只是通过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 \ Controllers \ Admin \ Image”
这行的意思是:
Image::make($file->getRealPath())->resize(300,function($constraint){
那为什么在我已经将其包含在项目中时为什么返回此错误呢?!
如果您知道的话,请告诉我...我真的很感谢。
谢谢
解决方法
在df['Day'] = df.index.date
df['Timetag'] = df.index.time
df = df.reset_index()[['Day','Timetag','Temp','Hum']]
print (df)
Day Timetag Temp Hum
0 2020-11-06 00:00:00 23.00 49.98
1 2020-11-06 11:00:00 21.92 52.06
上,您需要添加:
config/app.php
然后
$provides => [
Intervention\Image\ImageServiceProvider::class
],
现在,您可以在控制器顶部调用$aliases => [
'Image' => Intervention\Image\Facades\Image::class
]
了:
use Image;