Php 使用laravel 6的方法Illumb\Http\UploadedFile::resize不存在
我想添加一个用户(姓名、电子邮件、图像、多个图像…),我试图快速调整图像和多个图像的大小以便上传。我们使用软件包干预,我执行cmdPhp 使用laravel 6的方法Illumb\Http\UploadedFile::resize不存在,php,laravel,file-upload,intervention,Php,Laravel,File Upload,Intervention,我想添加一个用户(姓名、电子邮件、图像、多个图像…),我试图快速调整图像和多个图像的大小以便上传。我们使用软件包干预,我执行cmdphp composer require interference/image,我在config/app.php中添加了Intervention\Image\ImageServiceProvider::class和Image'=>Intervention\Image\Facades\Image::class,我还添加了use Intervention\Image\Ex
php composer require interference/image
,我在config/app.php
中添加了Intervention\Image\ImageServiceProvider::class
和Image'=>Intervention\Image\Facades\Image::class
,我还添加了use Intervention\Image\Exception\NotReadableException在RegisterController.php
中的code>,但它仍然给了我错误Method\Http\UploadedFile::resize不存在
它给了我错误方法\Http\UploadedFile::resize不存在
RegisterController.php
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['bail','required', 'string','min:3', 'max:50','regex:/^[\pL\s\-]+$/u'],
'email' => ['bail','required', 'string', 'email', 'max:255', 'unique:users'],
'telephone'=> ['bail','required','regex:/^06\d{8}$/','unique:users'],
'password' => ['bail','required', 'string', 'min:8', 'confirmed'],
'adressem' => ['bail','required', 'string', 'min:13','max:255'],
'adressem' => ['bail','required', 'string', 'min:13','max:255'],
'adresser' => ['bail','required', 'string', 'min:13','max:255'],
'image' => ['bail','required','mimes:jpeg,jpg,png,gif,svg','max:2048'],
'images.*' => ['bail','required','mimes:jpeg,jpg,png,gif,svg','max:2048']
]);
}
protected function create(array $data)
{
//image
$user = new User();
//$jdate = Carbon::now();
$request = app('request');
if($request->hasFile('image'))
{
$image = $request->file('image');
$url = Storage::put("user/" , $image->getClientOriginalName());
$image->resize(250,125);
$path = $request->image->store('profiles');
$user->image = $path;
}
$im = $user->image;
//images
$dataim = array();
if($request->hasFile('images'))
{
foreach($request->images as $file)
{
$file->resize(250,125);
$path = $file->store('profiles');
array_push($dataim,$path);
}
}
$user->images=json_encode($dataim);
$imm =$user->images;
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'telephone' => $data['telephone'],
'country_id' => $data['country_id'],
'state_id' => $data['state_id'],
'autrei' => $data['autrei'] ?? null,
'city_id' => $data['city_id'],
'autreh' => $data['autreh'] ?? null,
'adressem' => $data['adressem'],
'adresser' => $data['adresser'],
'image' => $im,
'images' => $imm
]);
}
跟着包裹走
首先,导入包
use Intervention\Image\Facades\Image;
之后,调整大小并保存
$image = Image::make($filename);
$image->resize(250,125, function($constraint){
$constraint->aspectRatio();
})->save($filename);
我发现您的RegisterController没有错误
您是否有用于调整图像大小的安装干预/图像
使用作曲家需要干预/图像
添加这些也使用图像强>
在寄存器控制器中
如果是:
config/app.php
return [
......
$provides => [
......
......,
'Intervention\Image\ImageServiceProvider'
],
$aliases => [
.....
.....,
'Image' => 'Intervention\Image\Facades\Image'
]
]