Admin does not update custom User fields
Closed this issue · 9 comments
The User class I am using with entrust gui has a first name and last name rather than just one field for a name. Creating a user with these fields is no issue, but when attempting to edit users, the fields for first name and last name do not update. Other fields do update.
Is there something I can do to enable editing of these "non-standard" User attributes?
Hi @jvalentinei
Have you tried editing your User model to include the first name and last name columns in the $fillable property?
Thanks for responding, I have added them to the $fillable property, but no success. Does that work for you?
I've just tried this out and I've got it working.
Here's the steps I took:
Create a migration:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddFirstNameToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('first_name');
$table->string('last_name');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('first_name');
$table->dropColumn('last_name');
});
}
}
Run the migration
php artisan migrate
Add the fields to the User
model's fillable property:
protected $fillable = ['name', 'email', 'password', 'first_name', 'last_name'];
Publish the views so they can be edited:
php artisan vendor:publish --tag="views"
Add the two fields to resources/views/vendor/entrust-gui/users/partials.form.blade.php
<div class="form-group">
<label for="first_name">First Name</label>
<input type="text" class="form-control" id="first_name" placeholder="First Name" name="first_name" value="{{ (Session::has('errors')) ? old('first_name', '') : $user->first_name }}">
</div>
<div class="form-group">
<label for="last_name">Last Name</label>
<input type="text" class="form-control" id="last_name" placeholder="Last Name" name="last_name" value="{{ (Session::has('errors')) ? old('name', '') : $user->last_name }}">
</div>
This is all done with the 5.2 branch.
Does this help you at all?
I tried your suggestion and it still didn't work for me. I do see the updated data in UserGateway::update(), but I did some logging of queries with middleware, and no update queries were fired.
Here's what I get:
firstname: does not update
lastname: does not update
email: does not update
password: does update
roles: does update
I think I ruled out any custom changes I may have made to the blades; I reverted to where it uses the default blades and the issue still occurs.
Does anything else come to mind?
I've just done another check and it seems that it's only updating when I enter a password.
I've pushed a fix so that it updates without the password as well.
Try doing a composer update and see if that sorts the issue for you!
I got this error when trying to save changes:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'password_confirmation' in 'field list' (SQL: update users
set firstname
= first2, updated_at
= 2016-06-16 18:16:07, password_confirmation
= y$d42EZyueggI32Wheb1qJZ.7XRj6vcaiIG5o.MqE7SazEUODtRTta. where id
= 23)
So it does look like it was trying to save the new name, which is a step in the right direction. Any idea on the db error?
I tried putting "password_confirmation" in the hidden property for User, but that didn't help.
Can you add
'confirmable' => false,
to your config/entrust-gui.php
file and see if that fixes it?
Make sure that password_confirmable
isn't in the user model's fillable property either
That works! I imagine it may need to work with the password confirmation in the future (somehow), but this works for what I need. Thanks much for the quick replies!
No problem, thanks for bringing this issue to my attention!