子域的Laravel 5认证不工作


Laravel 5 athentication in subdomain is not working

我在我的laravel 5项目中使用子域,但当我尝试登录用户时,它将不再进行身份验证。这是我的config'session.php

return [
'driver' => env('SESSION_DRIVER', 'database'),
'lifetime' => 120,
'expire_on_close' => false,
'encrypt' => true,
'files' => storage_path('framework/sessions'),
'connection' => null,
'table' => 'sessions',
'lottery' => [2, 100],
'cookie' => 'laravel_session',
'path' => '/',
'domain' => '.stagedevelopment.dev',
'secure' => false,
'http_only' => true,
];

my routes.php

Route::group([ 'prefix' => 'app', 'middleware' => 'auth' ], function() {
       ... some codes ....
    Route::group(['domain' => '{account_alias}.'.stagedevelopment.dev'], function () {
                    Route::get('dashboard', 'DashController@index');

这是DashController.php上的' DashController@index '

public function index(Request $request, $account_alias = null){
   if ( Auth::user()){
    // CODES TO CALL THE VIEW
   }
}

但是在登录时,它不会重定向到它。这使我感到不安。我也通过var_dump(Auth::user())检查,但它返回null值,但我尝试了var_dump($request->session()->get('uid')),它返回正在尝试身份验证的用户的user_id

我的问题是,我错过了什么吗?我只希望用户在Auth::user()中进行身份验证。请帮我一下。任何帮助都将不胜感激。提前谢谢你。

顺便说一下,这是登录用户的代码
public function postSignIn( Request $request) {
        $rules = array(
            'email' => 'required|email',
            'password' => 'required',
        );
        $validator = Validator::make( Input::all(), $rules );
        if ( $validator->passes() ){
            $remember = ( !is_null( $request->get('remember')) ? true : false );
            if ( Auth::attempt( array( 'email' => $request->input('email'), 'password' => $request->input('password') ) ) ){
                if ( Auth::check() ){
                        $account = 'App'Account::where( 'alias', 'LIKE', Auth::user()->account->alias )->get();
                        if($account->count() > 0){
                            return Redirect::to('http://'. Auth::user()->account->alias.'.stagedevelopment.dev/app/dashboard');
                        }
                }
            }
        }
    }

现在可以工作了。这只是我代码中的路由问题。在routes.php中的子域名必须是第一个,并且它的内部将是前缀等等,像这样:

Route::group(['domain' => '{account_alias}.'.env('APP_URL_NAME')], function () {
    // L3
    Route::group([ 'prefix' => 'app', 'middleware' => 'auth', 'middleware' => 'auth.manager' ], function() {
        Route::get('dashboard', 'DashController@index');