-
PHP Version8.2.0 CodeIgniter4 Version4.4.5 Shield Version1.0.1 Which operating systems have you tested for this bug?Windows Which server did you use?apache DatabaseMariaDB 10.2 Did you customize Shield?I customized the What happened?I altered the namespace App\Models;
use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
class UserModel extends ShieldUserModel
{
protected function initialize(): void
{
parent::initialize();
$this->returnType = \App\Entities\User::class;
$this->allowedFields = [
...$this->allowedFields,
'fullname', 'firstname', 'lastname', 'mobile',
];
$this->beforeInsert = [
...$this->beforeInsert,
'generateFullName'
];
$this->beforeUpdate = [
...$this->beforeUpdate,
'generateFullName'
];
}
protected function generateFullName(array $data)
{
if ( ! isset($data['data']['firstname']) || ! isset($data['data']['lastname'])) {
return $data;
}
$data['data']['fullname'] = $data['data']['firstname'].' '.$data['data']['lastname'];
return $data;
}
} Steps to ReproduceMake the Expected OutputThe full name gets generated and saved on the Anything else?No response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
When updating, if you use Entity in Models, only changed fields are processed. Try to set |
Beta Was this translation helpful? Give feedback.
When updating, if you use Entity in Models, only changed fields are processed.
Check the
$data
passed togenerateFullName()
.Try to set
$cleanValidationRules
tofalse
in the model.