-
I want to add some field to the user_identities model and when i read the doc, according the shield concept's, it posiible by using the user provider. But i don't really understand how to. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 13 replies
-
Hi @l-vanel,
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
// Add custom column for shield
class AddCustomColumnForUser extends Migration
{
public function up()
{
$fields = [
"gender SET('male', 'female', 'bisexual') NULL DEFAULT NULL COMMENT 'gender user'",
'first_name' => [
'type' => 'text',
'constraint' => '50',
'null' => TRUE
],
'last_name' => [
'type' => 'VARCHAR',
'constraint' => '50',
'null' => TRUE
],
'avatar' => [
'type' => 'VARCHAR',
'constraint' => '1000',
'null' => TRUE
],
'phone_number' => [
'type' => 'VARCHAR',
'constraint' => '20',
'null' => TRUE
],
'company' => [
'type' => 'VARCHAR',
'constraint' => '100',
'null' => TRUE
],
'description' => [
'type' => 'VARCHAR',
'constraint' => '1200',
'null' => TRUE
],
'code_meli' => [
'type' => 'VARCHAR',
'constraint' => '20',
'null' => TRUE
],
'birth_day date default NULL',
'country' => [
'type' => 'VARCHAR',
'constraint' => '20',
'null' => TRUE
],
'state' => [
'type' => 'VARCHAR',
'constraint' => '20',
'null' => TRUE
],
'city' => [
'type' => 'VARCHAR',
'constraint' => '20',
'null' => TRUE
],
'full_address' => [
'type' => 'VARCHAR',
'constraint' => '400',
'null' => TRUE
],
];
$this->forge->addColumn('users', $fields);
}
public function down()
{
$fields = [
'gender',
'first_name',
'last_name',
'company',
'phone_number',
'description',
'code_meli',
'birth_day',
'country',
'state',
'city',
'full_address',
];
$this->forge->dropColumn('users', $fields);
}
} 2 . Execute command <?php
declare(strict_types=1);
namespace App\Models;
use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
class UserModel extends ShieldUserModel
{
protected function initialize(): void
{
parent::initialize();
$this->allowedFields = [
...$this->allowedFields,
'gender',
'first_name',
'last_name',
'avatar',
'phone_number',
'company',
'code_meli',
'birth_day ',
'country',
'state',
'city',
'full_address',
// 'first_name',
];
}
}
public string $userProvider = \App\Models\UserModel::class; end of work. use CodeIgniter\Shield\Entities\User;
$users = model(\App\Models\UserModel::class);
$user = new User([
'username' => 'foo-bar',
'email' => '[email protected]',
'password' => 'secret plain text password',
'first_name' => 'Pooya',
'last_name' => 'Parsa',
]);
$users->save($user); more info see |
Beta Was this translation helpful? Give feedback.
-
hi , i have one problem , the code work but the data of new customs columns doesn't insert in the database. in other words ,only the username , email and password are insert in the database when i click on the register |
Beta Was this translation helpful? Give feedback.
-
Ok, thanks.
Le sam. 6 août 2022 à 00:49, Pooya Parsa Dadashi ***@***.***>
a écrit :
… OK, let me test myself by tomorrow. It is now 4:30 am.
—
Reply to this email directly, view it on GitHub
<#333 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOVUTKJA52X2G6ZK6QDDEQDVXWSCJANCNFSM55MLAR5A>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Your question is how can I save the values of gender, first_name, last_name and ... in the database in addition to email, username and password on the registration page. |
Beta Was this translation helpful? Give feedback.
Hi @l-vanel,
Thank you for registering your question again in this section.
app\Database\Migrations\AddCustomColumnForUser
with the following content: