Skip to content

Commit 5020b54

Browse files
committed
docs: add explanations
1 parent d1d1f96 commit 5020b54

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

docs/customization/adding_attributes_to_users.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ php spark db:table users
7474

7575
See [Customizing User Provider](./user_provider.md).
7676

77+
Don't forget to add the added attributes to the `$allowedFields` property.
78+
7779
## Update Validation Rules
7880

7981
You need to update the [validation rules](./validation_rules.md) for registration.

docs/customization/user_provider.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Customizing User Provider
22

3+
## Creating Your Own UserModel
4+
35
If you want to customize user attributes, you need to create your own
46
[User Provider](../getting_started/concepts.md#user-providers) class.
57
The 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

1416
The 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
1955
public string $userProvider = \App\Models\UserModel::class;

0 commit comments

Comments
 (0)