I have the following problem. I am using Backpack for Laravel with the PermissionManager Extension.
By default, you have to log in via your email address. However, you can change that to log in with a username. Works fine if I (for example) seed the database. But for some strange reason, I can not create new users via the PermissionManager PermissionManager Extension
. If I try the following error message is the result:
SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value (SQL: insert into
users
(updated_at
,created_at
) values (2018-11-29 22:26:32, 2018-11-29 22:26:32))
Just for testing, I gave the name
column a default value, but the error message is the same, except the error now is:
Field 'username' doesn't have a default value.
It just takes the next column in my database.
Of course, I've changed the CRUD-Requests, Form-Requests and so on, to store a username instead of an email. But it looks like the Request doesn't get my form values. It only tries to store the timestamps.
Strange thing: If I reverse all I did in the Controllers and so on and create an email column again, it will just work fine... did I overlook something? How can I solve this error and store users with a username instead of an email?
This is even odder... The data gets posted.
After taking a really close look at the error messages I found the following: As you can see, the array with my filled in data is still here. However, in the next instance, the parameters
array is completely empty as well as the $instance
array.
Step 1: In order to using username you have to edit app/Http/Controllers/Auth/LoginController and add a new method called username
public function username(){
return 'username';
}
Step 2: In User model make sure you use AuthenticatesUsers trait and add username field in fillable array. Step 3: Make sure in app/Http/Controllers/Auth/RegisterController you add the username validation and add username field in create method.
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'username' => $data['username'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
That's all. Hope it will solve your problem.
When this issue happened for me, I think I caused it by running php artisan vendor:publish
instead of following the instructions and running php artisan vendor:publish --provider="Backpack\\PermissionManager\\PermissionManagerServiceProvider
first.
My config/laravel-permission.php
file didn't just have the permission and user models incorrect, but the entire file was spatie's version instead of Laravel Backpack's version. My guess is that spatie's vendor:publish
register typically runs before Laravel Backpack PermissionManager's.
Never used this package before but I reviewed this package's files from github for solving your problem, i saw some thing in the UserCrudController.php
file. The file provides default user CRUD operations. The create and update form items define via setup method in this controller. But i don't see any define for username
field.
as I understand it, your user table has a username
and in your model $fillable
variable contains username
and the user create/update form does not post username
field to controller.
Can you try define username
form element in to UserCrudController.php
file for username
, or remove username
attribute from $fillable in your model.
I hope these solve your problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.