![](/img/trans.png)
[英]laravel when I use find I am getting this error: Call to undefined method Intervention\Image\ImageManager::find()
[英]Call to undefined method Intervention\Image\ImageManager::upload()
我正在嘗試將圖像上傳到數據庫中。 當我上傳時,出現以下錯誤
調用未定義的方法Intervention \\ Image \\ ImageManager :: upload()
在互聯網上搜索解決方案,我發現了這種方法
'Intervention\\Image\\ImageServiceProvider' in my $providers in config/app.php
添加這行'Intervention\\Image\\ImageServiceProvider' in my $providers in config/app.php
'Image' => 'Intervention\\Image\\Facades\\Image' in my $aliases in config/app.php
添加此行'Image' => 'Intervention\\Image\\Facades\\Image' in my $aliases in config/app.php
在我的控制器中,我也使用了Image。 但后來我仍然在上面出現此錯誤。 我可能想念什么?
調節器
public function uploadImagePost(UploadUserImageRequest $request)
{
$user = Auth::user();
$image = $request->file('profile_image');
if (false === empty($user->image_path)) {
$user->image_path->destroy();
}
$relativePath = 'uploads/users/' . $user->id;
$path = $relativePath;
$dbPath = $relativePath . DIRECTORY_SEPARATOR . $image->getClientOriginalName();
$this->directory(public_path($relativePath));
Img::upload($image, $path);
$user->update(['image_path' => $dbPath]);
return redirect()->route('my-account.home')
->with('notificationText', 'User Profile Image Uploaded successfully!!');
}
您使用的庫沒有upload()方法。 使用save()方法保存文件。
// read image from temporary file
$img = Image::make($_FILES['image']['tmp_name']);
// save image
$img->save('foo/bar.jpg');
請參閱此鏈接以獲取更多詳細信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.