我想添加一个用户(姓名、电子邮件、图像、多个图像…(,我尝试快速调整图像和多个图像的大小以上传。我们使用包干预,我执行cmdphp composer require intervention/image
,我在config/app.php中添加了InterventionImageImageServiceProvider::class
和Image'=>InterventionImageFacadesImage::class
,我还在RegisterController.php
中添加了use InterventionImageExceptionNotReadableException;
和use InterventionImageFacadesImage;
。
但它给我错误Command (Store) is not available for driver (Gd)
但它给我错误Command (Store) is not available for driver (Gd)
D:wampwwwaswaktinvendorinterventionimagesrcInterventionImageAbstractDriver.php:119
RegisterController.php
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['bail','required', 'string','min:3', 'max:50','regex:/^[pLs-]+$/u'],
'email' => ['bail','required', 'string', 'email', 'max:255', 'unique:users'],
'telephone'=> ['bail','required','regex:/^06d{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 = Image::make($image);
$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 = Image::make($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
]);
}
问题是,您使用Intervention实例覆盖上传的文件实例($file
(,但随后尝试在该Intervention映像实例上调用store
(和UploadedFile
方法(。您需要为干预图像实例实例使用不同的变量名。