11# Customizing User Provider
22
3+ ## Creating Your Own UserModel
4+
35If you want to customize user attributes, you need to create your own
46[ User Provider] ( ../getting_started/concepts.md#user-providers ) class.
57The only requirement is that your new class MUST extend the provided ` CodeIgniter\Shield\Models\UserModel ` .
@@ -13,8 +15,42 @@ php spark shield:model UserModel
1315
1416The class name is optional. If none is provided, the generated class name would be ` UserModel ` .
1517
16- After creating the class, set the ` $userProvider ` property in ** app/Config/Auth.php** as follows:
18+ ## Configuring to Use Your UserModel
19+
20+ After creating the class, set your model classname to the ` $userProvider ` property
21+ in ** app/Config/Auth.php** :
1722
1823``` php
1924public string $userProvider = \App\Models\UserModel::class;
2025```
26+
27+ ## Customizing Your UserModel
28+
29+ Customize your model as you like.
30+
31+ If you add attributes, don't forget to add the attributes to the ` $allowedFields `
32+ property.
33+
34+ ``` php
35+ <?php
36+
37+ declare(strict_types=1);
38+
39+ namespace App\Models;
40+
41+ use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
42+
43+ class UserModel extends ShieldUserModel
44+ {
45+ protected function initialize(): void
46+ {
47+ parent::initialize();
48+
49+ $this->allowedFields = [
50+ ...$this->allowedFields,
51+ 'first_name', // Added
52+ 'last_name', // Added
53+ ];
54+ }
55+ }
56+ ```
0 commit comments