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,7 +15,41 @@ 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+ ## Customizing Your UserModel
19+
20+ Customize your model as you like.
21+
22+ If you add attributes, don't forget to add the attributes to the ` $allowedFields `
23+ property.
24+
25+ ``` php
26+ <?php
27+
28+ declare(strict_types=1);
29+
30+ namespace App\Models;
31+
32+ use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
33+
34+ class UserModel extends ShieldUserModel
35+ {
36+ protected function initialize(): void
37+ {
38+ parent::initialize();
39+
40+ $this->allowedFields = [
41+ ...$this->allowedFields,
42+ 'first_name', // Added
43+ 'last_name', // Added
44+ ];
45+ }
46+ }
47+ ```
48+
49+ ## Configuring to Use Your UserModel
50+
51+ After creating the class, set your model classname to the ` $userProvider ` property
52+ in ** app/Config/Auth.php** :
1753
1854``` php
1955public string $userProvider = \App\Models\UserModel::class;
0 commit comments