laravel 社会名流不了解

qnyhuwrf  于 2023-01-27  发布在  其他
关注(0)|答案(2)|浏览(127)

我已经尝试了我在网上找到的所有东西,但似乎都不起作用。。这是我的问题:我试图在Laravel使用社交名媛实现与谷歌的身份验证,但我遵循thoses步骤描述:here
这是我的 composer json:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^7.3|^8.0",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "jeroennoten/laravel-adminlte": "^3.7",
        "laravel/framework": "^8.75",
        "laravel/sanctum": "^2.11",
        "laravel/socialite": "^5.5",
        "laravel/tinker": "^2.5",
        "laravel/ui": "^3.4"
    },
    "require-dev": {
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^5.10",
        "phpunit/phpunit": "^9.5.10"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

这里是我的文件config/app.php:

'providers' => [
//...
        Laravel\Socialite\SocialiteServiceProvider::class,
//...

    ],
'aliases' => [

//..
        'Socialite' => Laravel\Socialite\Facades\Socialite::class,
      //...

    ],

这是我的控制器,这就是我得到我的错误,在此行“Socialite::driver($provider)-〉redirect()":

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Socialite;

class SocialiteController extends Controller
{
    protected $providers = ["google"];
    public function loginRegister(){
        return view ("socialite.login-register");
    }

    public function redirect (Request $rq){
        $provider = $rq->provider;
        if(in_array($provider,$this->providers)){
            return Socialite::driver($provider)->redirect();
        }
    }
}

以下是错误的屏幕截图:

Laravel找不到门面社交,即使我试图手动导入它,就像这样=〉“Laravel\社交\门面\社交”..我试图再次下载该软件包,并尝试了一些cmd像 composer 转储-自动加载..,尝试重新生成所有类的列表,需要包括在该项目中,但它不会工作。

qni6mghb

qni6mghb1#

正如错误所示,它没有找到Socialite包,请尝试在控制器的开头添加该包的用法:

use Laravel\Socialite\Facades\Socialite;
col17t5w

col17t5w2#

我也有这个问题,但我解决了一些愚蠢的解决方案。首先,你应该用这个命令安装软件包

composer require laravel/socialite

然后你应该关闭你的IDE。然后你应该再次打开IDE。我总是这样做的解决方案。最后工作。

相关问题