Laravel登录重定向回登录页面

时间:2018-02-19 14:32:02

标签: php laravel login laravel-5.4 laravel-5.5

我是Laravel 5.5的初学者。*我正在尝试创建一个登录页面 每当我点击登录按钮时,我都会被重定向回登录表单。

以下是我的步骤:

  1. php artisan make:auth
  2. php artisan make:migration table_name_here
  3. 我修改了迁移
  4. php artisan migrate
  5. 这是我的LoginController

    <?php
    
    namespace App\Http\Controllers\Auth;
    
    use App\Http\Controllers\Controller;
    use Illuminate\Foundation\Auth\AuthenticatesUsers;
    use Illuminate\Http\Request;
    use Auth;
    
    class LoginController extends Controller
    {
        /*
        |--------------------------------------------------------------------------
        | Login Controller
        |--------------------------------------------------------------------------
        |
        | This controller handles authenticating users for the application and
        | redirecting them to your home screen. The controller uses a trait
        | to conveniently provide its functionality to your applications.
        |
        */
    
        use AuthenticatesUsers;
    
        /**
         * Where to redirect users after login.
         *
         * @var string
         */
        protected $redirectTo = '/home';
    
        /**
         * Create a new controller instance.
         *
         * @return void
         */
        public function __construct()
        {
            $this->middleware('guest')->except('logout');
        }
    
    }
    

    这是我的用户模型

    <?php
    
    namespace App;
    
    use Illuminate\Notifications\Notifiable;
    use Illuminate\Foundation\Auth\User as Authenticatable;
    
    class User extends Authenticatable
    {
        use Notifiable;
    
        /**
         * The attributes that are mass assignable.
         *
         * @var array
         */
        protected $fillable = [
            'firstname', 'lastname', 'email', 'password', 'department', 'phone', 'status', 'roleId',
        ];
    
        /**
         * The attributes that should be hidden for arrays.
         *
         * @var array
         */
        protected $hidden = [
            'password', 'remember_token',
        ];
    }
    

    我的web.php

    <?php
    
    /*
    |--------------------------------------------------------------------------
    | Web Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register web routes for your application. These
    | routes are loaded by the RouteServiceProvider within a group which
    | contains the "web" middleware group. Now create something great!
    |
    */
    
    Route::get('/', function () {
        return view('welcome');
    });
    
    
    Auth::routes();
    
    Route::get('/home', 'HomeController@index')->name('home');
    

    我的表格列

    STAFFID, 角色ID, 名字, 姓, 用户名, 电子邮件, 部门, 电话, 状态, remember_token, created_at, 的updated_at, 密码,

4 个答案:

答案 0 :(得分:0)

只需重新启动apache服务器并再次运行php artisan serve命令,这可以帮助您缩短问题。

答案 1 :(得分:0)

我遇到的问题是,登录名没有任何错误地重定向到登录页面。

对我来说,我的表单输入字段中没有任何名称标签,例如 因此它不知道要在请求中发送哪些数据

key :=&datastore.Key{Kind:"session",Parent:nil,Namespace:userID}
client.Put(ctx,key,&sessionUser)

应该是

<input type="email">
<input type="password">

答案 2 :(得分:0)

因此,当我在本地开发环境中的session.php中将SESSION_DOMAIN设置为“ NULL”时,我就能解决此问题。

答案 3 :(得分:0)

在从旧服务器迁移到新生产服务器到新服务器时,设置SESSION_SECURE_COOKIE=true时遇到了同样的问题。未设置HTTPS。

通过删除SESSION_SECURE_COOKIE=true,登录可以再次开始工作。

当然,在实际迁移服务器之前,先设置HTTPS并添加env var。