我没有使用默认路由进行登录和注销,并且我构建的这些自定义路由工作正常。我正在使用社交名流在我的应用程序中实现谷歌登录。这是关于 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/