Laravel 7 query builder ignoring new data

Viewed 71

I was trying to create new input to default registration form (This is similar How to add new input in register page laravel?). But SQL command created by code below don't add my new data in command.

protected function create(array $data) 
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'address' => $data['address'],
        'password' => bcrypt($data['password'])
    ]);
}

In SQL i get something like INSERT INTO "user" ("name","email","password") VALUES ... and adress is ignored.

1 Answers

Add fillable property in User Model

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'address'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
    
}
Related