Have you tried clearing your browser cache? Maybe also resetting your password.
Mar 9, 2020
15
Level 2
Login fails after changing User model
I have expanded default User model in Laravel with additional fields like firstname, lastname, admin (boolean field) etc.
Registration and works fine, and it logs me in for the first time, but if I log out, I can't login anymore. I get the "These credentials do not match our records." error when I try to login. What could be wrong?
My user model is modified and looks like this:
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'firstname', 'lastname', 'email', 'password', 'admin', 'active', 'phone'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* Add a mutator to ensure hashed passwords
*/
public function setPasswordAttribute($password)
{
$this->attributes['password'] = bcrypt($password);
}
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
Migration model looks like this:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->unique();
$table->string('firstname')->nullable();
$table->string('lastname')->nullable();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->boolean('admin')->default(false);
$table->boolean('active')->default(true);
$table->string('phone')->nullable();
$table->rememberToken();
$table->timestamps();
$table->string('edited_by')->nullable();
$table->timestamp('edited_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
Level 53
@mleontenko open your RegisterController, go to create method and update 'password' => Hash::make($data['password']), to 'password' => $data['password'],.
2 likes
Please or to participate in this conversation.