这是laravel中的默认用户模型,可以添加到fillable array
。
我想创建一个登录和注册页面
每当我添加fillable array
时
我的代码似乎没有用,这可能是问题
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
我希望它看起来像这样 使用Illuminate \ Notifications \ Notifiable; 使用Illuminate \ Foundation \ Auth \ User作为Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'firstname', 'lastname', 'email', 'password', 'department', 'phone', 'status', 'username';
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
答案 0 :(得分:2)
您使用了错误的语法。从结尾删除;
以使其正常工作:
'username';
答案 1 :(得分:2)
更改
protected $fillable = [
'firstname', 'lastname', 'email', 'password', 'department', 'phone', 'status', 'username';
];
要
protected $fillable = [
'firstname', 'lastname', 'email', 'password', 'department', 'phone', 'status', 'username'
];
您在;
之后添加了分号username
,这会给您一个错误
答案 2 :(得分:0)
是的,您可以使用多少元素到您的fillable和保护的模型属性,因为您只需从代码中删除;(分号)并写如
protected $fillable = [
'firstname', 'lastname', 'email', 'password', 'department', 'phone', 'status', 'username'
];