【问题标题】:Class 'Image' not found laravel 5.3找不到类“图像”laravel 5.3
【发布时间】:2018-05-28 12:47:07
【问题描述】:

使用 laravel 5.3

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

我其实已经添加了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()) );
    }
}

【问题讨论】:

    标签: laravel laravel-5.3


    【解决方案1】:

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

    将此添加到$providers 数组中。

    Intervention\Image\ImageServiceProvider::class
    

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

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

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

    【讨论】:

    【解决方案2】:

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

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

    composer require intervention/image
    

    现在我假设你已经通过上面的命令成功安装了。

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

    配置/app.php 在提供者数组中添加此服务提供者:

    'Intervention\Image\ImageServiceProvider'
    

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

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

    【讨论】:

    • 这对我有用...我也按照您的指示进行了制作。非常感谢。 @foram
    • @kinnariPrajapati 欢迎您。如果它对您有用,请在此解决方案上打勾。谢谢
    • 我没有足够的声誉......当我获得它时。 .我一定会回来给你的答案打分。 @foram
    猜你喜欢
    • 2017-01-01
    • 2017-06-07
    • 1970-01-01
    • 2017-03-26
    • 2015-02-07
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多