gpt4 book ai didi

laravel - 类 'Image' 未找到 laravel 5.3

转载 作者:行者123 更新时间:2023-12-03 15:45:40 25 4
gpt4 key购买 nike

使用 Laravel 5.3

FatalErrorException in UserProfileController.php line 26: Class 'Image' not found



我实际上已经添加了 使用图像;

namespace App\Http\Controllers\Profile;

use App\Photo;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Image;



class UserProfileController extends Controller
{
//
public function profile(){
return view('profile', array('user' => Auth::user()) );
}
public function update_avatar(Request $request){
// Handle the user upload of avatar
if($request->hasFile('avatar')){
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300, 300)->save( public_path('/uploads/avatars/' . $filename ) );
$user = Auth::user();
$user->avatar = $filename;
$user->save();
}
return view('profile', array('user' => Auth::user()) );
}
}

最佳答案

composer require intervention/image 然后打开config/app.php文件。

将此添加到 $providers大批。

Intervention\Image\ImageServiceProvider::class

接下来将其添加到 $aliases 数组中。
'Image' => Intervention\Image\Facades\Image::class

然后 composer dump-autoload并确保在 Controller 顶部调用它: use Intervention\Image\ImageManagerStatic as Image;

关于laravel - 类 'Image' 未找到 laravel 5.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50566854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com