samedi 3 octobre 2020

Laravel authentication bug?

I had a problem, I spent 2 hours solving it, but I can't understand it. Why is this happening?

I have built-in LoginController. It uses "use AuthenticatesUsers". And there is a "attemptLogin" method inside it:

protected function attemptLogin(Request $request)
{
    return $this->guard()->attempt(
        $this->credentials($request), $request->filled('remember')
    );
}

If I remove $request->filled('remember'), everything works for me. Could you explain why this is happening, please?

view

   <div class="auth"> <!-- Authorization window -->
                <div class="auth__title">Authorization</div>
                <form method="POST" action="">
                    @csrf
                    <p>Login</p>
                    <input name='username' type="text">
                    <p>Password</p>
                    <input name='password' type="text">
                    <a class="auth__forget-link" href="#">Forgot?</a>
                    <button class="auth__submit button" type="submit">Log in</button>
                </form>
    </div>  <!-- Authorization window -->

model

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */

    public $timestamps = false;

    protected $fillable = [
        'username','password','name','email','position'
    ];

    protected $hidden = [
        'password','remember_token',
    ];

    public function projects() {
        return $this->hasMany('App\Project','user_id');
    }

}

migration

Schema::create('users', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('username')->unique();
        $table->string('password');
        $table->string('fio');
        $table->string('email')->unique();
        $table->string('api_token')->nullable();
        $table->string('position')->nullable();
        $table->enum('role', ['admin', 'supervisor']);
        $table->rememberToken();
    });

P.S. Sorry for the trouble with the model code, I don't know how to insert this correctly




Aucun commentaire:

Enregistrer un commentaire