Reputation: 1281
I'm adding some authentication to my Laravel 5.4 project. However, when updating the provided User.php file's (which is an Eloquent model) $fillable array to correspond to my new Users table migration, the insert query upon registering a new user doesn't propagate the changes. See below.
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'api_token' => str_random(60),
'password' => bcrypt($data['password'])
]);
}
I've added 'api-token' to my database, and updated my model's $fillable array as well
protected $fillable = [
'name', 'email', 'password', 'api-token',
];
and my migration has been refreshed with the changes which was adding the 'api-token' field
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->string('api_token', 60)->unique();
$table->rememberToken();
$table->timestamps();
});
However I still get the same error, which is:
null value in column "api_token" violates not-null constraint
(SQL: insert into "users" ("name", "email", "password", "updated_at", "created_at") values (Bradley, [email protected], $2y$10$IBq0yEumngpeWf/oql1HgeMRYP1ANj.owXqkMc7gtIN/kxcW46Giu, 2017-05-03 13:37:56, 2017-05-03 13:37:56) returning "id")
The error clearly shows the api_token
field isn't even being considered when inserting a new User. Have I missed some sort of update to Laravel that I need to do after making changes to a model in order for it to take effect?
Upvotes: 0
Views: 377
Reputation: 5083
In your fillable you added api-token
while in your migration and creation you use api_token
.
Notice the difference between the -
and _
.
Upvotes: 1