哨兵和 Laravel 5.2

Sentinel and Laravel 5.2

我无法让 Sentinel 工作。我不知道该怎么办了,我尝试了一切,希望其他人有一些建议。 问题出在检查方法为假的在线中间件中...

编辑:我发现问题是会话在中间件中不起作用,但仍然没有解决方案

EDIT2:看起来像它的许可,我在 ubuntu,我在 win10 上有 运行 与 xampp 相同的代码,一切正常,仍然没有 [=28] 的解决方案=]

routes.php

Route::group(['middleware' => ['web']], function () {

Route::get('/',          ['as' => 'index'    , 'uses' => 'UserController@index']);
Route::post('login',     ['as' => 'login'    , 'uses' => 'UserController@login']);
Route::post('register',  ['as' => 'register' , 'uses' => 'UserController@register']);
Route::get('logout',    ['as' => 'logout'   , 'uses' => 'UserController@logout']);

Route::group(['prefix' => 'viva' , 'middleware' => ['online']], function () {
    Route::get('/',     ['as' => 'dashboard'    , 'uses' => 'VivaController@dashboard']);
});
});

登录方式

public function login(){
    $data = Input::all();

    $credentials = [
        'email'    => $data["username"],
        'password' => $data["password"],
    ];

    $user = Sentinel::authenticate($credentials);

    if (!empty($user)){
        Sentinel::login($user);
        //dd(Sentinel::check()); //---> this gives logged user...
        return Redirect::route('dashboard');
    }
    else{
        return Redirect::back()->withErrors(['fail', 'Neuspjela prijava! Molimo pokušajte ponovo.']);
    }


}

online.php 中间件

 class online
{
/**
 * Handle an incoming request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @return mixed
 */
public function handle($request, Closure $next )
{
    dd(Sentinel::check()); //---> this is always false


    if (Sentinel::check())
    {
        return Redirect::route('dashboard');
    }
    else
    {
        return Redirect::route('index')->withErrors(['fail', 'Nemate prava na pristup ovim stranicama!']);
    }

    return $next($request);

}
}

对于会话,我相信您可能需要这些权限。

注:假设Laravel安装在/var/www/laravel

cd /var/www/laravel
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache