Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add new fields #430

Closed
cod3rshotout opened this issue Sep 9, 2021 · 4 comments
Closed

Cannot add new fields #430

cod3rshotout opened this issue Sep 9, 2021 · 4 comments

Comments

@cod3rshotout
Copy link

I'm trying to add first_name and last_name but without success.
What I did:

<?php

namespace App\Entities;

use Myth\Auth\Entities\User as MythUser;

class User extends MythUser
{
    protected $firstName;

    protected $lastName;
}

and then new UserModel:

<?php

namespace App\Models;

use Myth\Auth\Models\UserModel as BaseModel;
use App\Entities\User;

class UserModel extends BaseModel
{
    protected $returnType = User::class;

    protected $allowedFields = [
        'email', 'username', 'password_hash', 'reset_hash', 'reset_at', 'reset_expires', 'activate_hash',
        'status', 'status_message', 'active', 'force_pass_reset', 'permissions', 'deleted_at', 'first_name',
        'last_name'
    ];

when I try to update:

$user = new \App\Entities\User();
$user->email = $this->request->getPost('email');
$user->username = $this->request->getPost('username');
$user->firstName = $this->request->getPost('first_name');
$user->lastName = $this->request->getPost('last_name');

if ($this->users->skipValidation(true)->update(user()->id, $user)) {
    return redirect()->back()->with('sweet-success', lang('dashboard.user.msg.msg_update'));
}

all the fields are update except for firstName and lastName, why?

NB: the object user actually contains those properties correctly

@lonnieezell
Copy link
Owner

Did you create a migration to add those fields to the user table in the database?

@rodrigozem
Copy link

rodrigozem commented Sep 9, 2021

I had the same problem yesterday

@lonnieezell
Copy link
Owner

No need to set the $firstName and $lastName properties on the User Entity. They are cased differently than the fields you're trying to save to the database anyway, but having them there could potentially cause issues with the magic get/set functions. All of that data is stored in the Entity's $attributes array automatically.

@MGatner
Copy link
Collaborator

MGatner commented Jul 12, 2022

Extended fields work fine, you probably need to set $personalFields in your config file.

This is a support problem; if you still have issues please take it to the CodeIgniter forums or Slack.

@MGatner MGatner closed this as completed Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants