1
我不能讓哨兵工作。我不知道該做什麼,我試了一切,希望別人有一些建議。 問題在網上中間件,其中檢查方法是假的......哨兵和拉拉維爾5.2
編輯:我發現了問題是會話不會在中間件工作,還是無解壽
EDIT2:看起來像它permisions,我是在Ubuntu的,我已經在win10運行與XAMPP相同的代碼,一切工作正常,仍然無解的Ubuntu
routes.php文件
Route::group(['middleware' => ['web']], function() {
Route::get('/', ['as' => 'index' , 'uses' => '[email protected]']);
Route::post('login', ['as' => 'login' , 'uses' => '[email protected]']);
Route::post('register', ['as' => 'register' , 'uses' => '[email protected]']);
Route::get('logout', ['as' => 'logout' , 'uses' => '[email protected]']);
Route::group(['prefix' => 'viva' , 'middleware' => ['online']], function() {
Route::get('/', ['as' => 'dashboard' , 'uses' => '[email protected]']);
});
});
登錄方法
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);
}
}