0

I have a Laravel 4 app that uses the Auth class. I have setup the db stuff and login, etc. Now I'm trying to check if the user is logged in or not using the Auth::check() method.

For some reason when I'm logged in one of my controllers returns true and another returns false.

routes.php

// Route group for API versioning
Route::group(array('prefix' => 'api/v1'), function() {

    Route::resource('template', 'TemplateController');

});

// Authentication

Route::group(array('domain' => 'login.mailstash.dev'), function() {
    Route::get('register', array('as'=>'register', 'uses'=>'AuthController@getRegister'));
    Route::post('register', array('uses'=>'AuthController@postRegister'));
    Route::get('/', array('as'=>'login', 'uses'=>'AuthController@getLogin'));
    Route::post('login', array('uses'=>'AuthController@postLogin'));
    Route::get('logout', array('as'=>'logout', 'uses'=>'AuthController@getLogout'));
});

Route::group(array('domain' => 'app.mailstash.dev'), function()
{
    Route::get('/', array('as'=>'home', 'uses'=>'IndexController@home'));
});

AuthController.php

<?php

class AuthController extends BaseController {

    protected $layout = 'layouts.fluid-angular';


    public function getLogin() {

        var_dump(Auth::check());die(); // returns true


        if (Auth::check())
        {
            return Redirect::route('home');
        }


        $this->layout->content =  View::make('auth/login')
                    ->with('menu', 'login')
                    ->with('title', 'Log In');
    }
}

IndexController.php

class IndexController extends BaseController 
{
    protected $layout = 'layouts.fluid-angular';

    public function home() {

        var_dump(Auth::check());die(); // returns false

        $this->layout->content = View::make('templates/index');
    }
}

Can anyone see why AuthController would return true but IndexController would return false?

4

1 回答 1

1

更改您的设置,以便您的 cookie 在两个子域上都有效。

于 2013-05-24T14:58:05.557 回答