子域中的Laravel 5弱化不起作用 [英] Laravel 5 athentication in subdomain is not working

查看:89
本文介绍了子域中的Laravel 5弱化不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using a subdomain in my laravel 5 project but when I try to loggin a user, it won't authenticate anymore. This is my 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,
];

我的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

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.

but when signing in, it won't redirect on it. this make me issue. I also check by var_dump(Auth::user()) but it returns null value but I tried var_dump($request->session()->get('uid')) it returns the user_id of the user who is trying to authenticate.

我的问题是,我错过了什么吗?我只希望对用户进行身份验证才能在Auth::user()中使用.请帮我解决一下这个.任何帮助将不胜感激.预先谢谢你.

my question is, did I missed something? I just want the user to be authenticated to be in the Auth::user(). please help me with this. any help will be appreciated. thank you in advance.

顺便说一下,这是我用于登录用户的代码

by the way, this is my code for loggin a 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中的子域必须是第一个子域,并且在其内部将是前缀等,如下所示:

it works now. it just a routes issue on my code. the subdomain in routes.php must be the first and inside on it will be the prefix and etc. like this:

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');

这篇关于子域中的Laravel 5弱化不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆