2017-07-13 42 views
1

我沒有使用默認路由進行登錄和註銷,這些自定義路由的構建工作正常。我正在使用社交網站在我的應用中實施Google登錄。這是關於谷歌登錄的web.php片段:ReflectionException類LoginController不存在

Route::get('/auth/google', '[email protected]')->name('googleauth')->middleware('guest'); 

Route::get('/auth/google/callback', '[email protected]')->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> 

這是我的控制器位於應用程序/ HTTP /控制器/ 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控制檯生成了一個祕密和客戶端ID。少了什麼東西?我實在無法理解,爲什麼它不工作

回答

1

您必須附加的命名空間中的路徑聲明:

Route::get('/auth/google', 'Auth\[email protected]')->name('googleauth')->middleware('guest'); 
Route::get('/auth/google/callback', 'Auth\[email protected]')->name('googlecall'); 

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

Route::namespace('Auth')->group(function() { 
    Route::get('/auth/google', '[email protected]'); 
    Route::get('/auth/google/callback', '[email protected]'); 
}); 
+1

非常感謝!問題解決了 –

+0

很高興幫助:)快樂的編碼 –

相關問題