Laravel - 登录后没有重定向

时间:2016-11-17 15:52:42

标签: php laravel laravel-5.3 http-status-code-302

当我登录时,我无法重定向到页面。在检查员网络中,页面显示但找到了302代码。

enter image description here

当我执行dd()时,auth :: attempt()和auth :: check()都返回true。

我的代码是:

    Route::post('/login', function()
{
  //echo "login...";
  $username = Input::get('username');
  $password = Input::get('password');
  $remember = Input::get('remember');

  $userdata = array(
    'username'  => Input::get('username'),
    'password'  => Input::get('password')
  );
  $rules = array(
        'username' => 'required|exists:us,username',
        'password' => 'required'
  );

  $validator = Validator::make($userdata, $rules);

  if ($validator->passes())
  {
    //dd(Auth::attempt(['username' => $username, 'password' => $password], $remember));
    if(Auth::attempt(['username' => $username, 'password' => $password], $remember))
    {
      //echo "ok";
      //dd(Auth::check());
      return Redirect::to('app/');
    }
  }
  else
  {
    //echo "error";
    return Redirect::to('login')->withErrors($validator);
  }
});

1 个答案:

答案 0 :(得分:0)

试试这个:

  

Route.php

Route::group(['middleware' => 'auth'], function() {
    Route::get('app/groups', function() { 
        return view('app.main-folders'); 
    });
});

Middleware