找不到类“图像”laravel 5.3

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50566854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:45:38  来源:igfitidea点击:

Class 'Image' not found laravel 5.3

laravellaravel-5.3

提问by Leo

Using laravel 5.3

使用 Laravel 5.3

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

UserProfileController.php 第 26 行中的 FatalErrorException:未找到“图像”类

I actually have added use Image;

我实际上已经添加了use Image;

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()) );
    }
}

回答by Leo

composer require intervention/imagethen open the config/app.phpfile.

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

Add this to the $providersarray.

将此添加到$providers数组中。

Intervention\Image\ImageServiceProvider::class

Next add this to the $aliases array.

接下来将其添加到 $aliases 数组中。

'Image' => Intervention\Image\Facades\Image::class

then composer dump-autoloadand make sure you call it at the top of your controller : use Intervention\Image\ImageManagerStatic as Image;

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

回答by foram kantaria

Step 1: Installation In this step you will have to configure intervention/image library in your application.

第 1 步:安装 在此步骤中,您必须在应用程序中配置干预/图像库。

You will have to run below command in your terminal promt.

您必须在终端提示中运行以下命令。

composer require intervention/image

Now i assume that you have successfully installed by above command.

现在我假设您已通过上述命令成功安装。

OK, now i will configure service provider with their aliases name in following path config/app.php .

好的,现在我将在以下路径 config/app.php 中使用他们的别名配置服务提供者。

config/app.php Add this service provider in provider array :

config/app.php 在 provider 数组中添加这个服务提供者:

'Intervention\Image\ImageServiceProvider'

Now add facade to aliases array.

现在将外观添加到别名数组。

'Image' => 'Intervention\Image\Facades\Image'