php - ReflectionException 类 LoginController 不存在

标签 php laravel-5.4 laravel-socialite

我没有使用默认路由进行登录和注销,并且我构建的这些自定义路由工作正常。我正在使用社交名流在我的应用程序中实现谷歌登录。这是关于 google 登录的 web.php 片段:

Route::get('/auth/google', 'LoginController@redirectToGoogle')->name('googleauth')->middleware('guest');

Route::get('/auth/google/callback', 'LoginController@handleGoogleCallback')->name('googlecall');

这是我在登录 View 中得到的内容:

<form id="googleLoginForm" name="googleLoginForm" method="GET" action="{{ route('googleauth') }}">
    {!! csrf_field() !!}
    <br> <br>
    <button id="btnGoogleLogin" name="btnGoogleLogin" type="submit" class="btn btn-default">G login</button>
</form>

这是我的 Controller ,位于 app/http/controllers/auth:

namespace MyApp\Http\Controllers\Auth;

use MyApp\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Socialite;

class LoginController extends Controller
{
    use AuthenticatesUsers;
    protected $redirectTo = '/home';

    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function redirectToGoogle(){
        return Socialite::driver('google')->redirect();
    }

    public function handleGoogleCallback(){
        $user = Socialite::driver('google')->user();
        $user->token; 
    }

}

我认为我已经正确安装了社交名流,我还使用 google api 控制台生成了一个 secret 和一个客户端 ID。少了什么东西?我真的不明白为什么它不起作用

最佳答案

您必须在路由声明中附加 namespace :

Route::get('/auth/google', 'Auth\LoginController@redirectToGoogle')->name('googleauth')->middleware('guest');
Route::get('/auth/google/callback', 'Auth\LoginController@handleGoogleCallback')->name('googlecall');

或者你可以group them by namespace ,例如:

Route::namespace('Auth')->group(function () {
    Route::get('/auth/google', 'LoginController@redirectToGoogle');
    Route::get('/auth/google/callback', 'LoginController@handleGoogleCallback');
});

关于php - ReflectionException 类 LoginController 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45075888/

相关文章:

laravel-5 - 如何使用 Laravel 社交名流检索用户 github 存储库?

php - 自动加载语言代码点火器

php - 显示数据库表中的动态范围并计算每个范围内的行数

php - 拉维尔 5.4 : JWT API with multi-auth on two tables one works the other not

php - 或者在带有子查询的 Laravel 查询生成器中的 WHERE IN

php - Laravel Mailer 不发送或重定向

php - Laravel Socialite - 不支持驱动程序 [youtube]

facebook - Laravel 5.1 - 通过 Socialite 进行 Facebook 身份验证

php - 使用 PHP 远程 SSL 连接到 AWS( key 对)

php - mysql中使用UNION时无法order by