ReflectionException Class LoginController 不存在
ReflectionException Class LoginController does not exist
我没有使用默认路由进行登录和注销,我构建的这些自定义路由工作正常。我正在使用社交名流在我的应用程序中实现 google 登录。这些是关于 google 登录的 web.php 片段:
Route::get('/auth/google', 'LoginController@redirectToGoogle')->name('googleauth')->middleware('guest');
Route::get('/auth/google/callback', 'LoginController@handleGoogleCallback')->name('googlecall');
这是我在登录视图中得到的:
<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>
这是我的控制器,位于 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;
}
}
我想我已经正确安装了 socialite,我还使用 google api 控制台生成了一个密码和一个客户端 ID。少了什么东西?我真的不明白为什么它不起作用
您必须在路由声明中附加命名空间:
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');
});
我没有使用默认路由进行登录和注销,我构建的这些自定义路由工作正常。我正在使用社交名流在我的应用程序中实现 google 登录。这些是关于 google 登录的 web.php 片段:
Route::get('/auth/google', 'LoginController@redirectToGoogle')->name('googleauth')->middleware('guest');
Route::get('/auth/google/callback', 'LoginController@handleGoogleCallback')->name('googlecall');
这是我在登录视图中得到的:
<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>
这是我的控制器,位于 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;
}
}
我想我已经正确安装了 socialite,我还使用 google api 控制台生成了一个密码和一个客户端 ID。少了什么东西?我真的不明白为什么它不起作用
您必须在路由声明中附加命名空间:
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');
});