Skip to content

Commit 0da847b

Browse files
authored
Merge pull request #604 from kenjis/fix-docs-user-provider
docs: improve User Provider
2 parents 08bbc37 + 3f4f23b commit 0da847b

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

docs/concepts.md

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This document covers some of the base concepts used throughout the library.
1313

1414
Shield is designed so that the initial setup of your application can all happen in code with nothing required to be
1515
saved in the database. This means you do not have to create large seeder files that need to run within each environment.
16+
1617
Instead, it can be placed under version control, though the Settings library allows those settings to be easily stored
1718
in the database if you create an interface for the user to update those settings.
1819

@@ -24,25 +25,10 @@ on the standard Config class if nothing is found in the database.
2425

2526
## User Providers
2627

27-
You can use your own models to handle user persistence. Shield calls this the "User Provider" class.
28-
A default model is provided for you by the `CodeIgniter\Shield\Models\UserModel` class. You can change
29-
this in the `Config\Auth::$userProvider` setting. The only requirement is that your new class
30-
MUST extend the provided `UserModel`.
31-
32-
Shield has a CLI command to quickly create a custom `UserModel` class by running the following
33-
command in the terminal:
34-
35-
```console
36-
php spark shield:model UserModel
37-
```
38-
39-
The class name is optional. If none is provided, the generated class name would be `UserModel`.
40-
41-
You should set `Config\Auth::$userProvider` as follows:
28+
Shield has a model to handle user persistence. Shield calls this the "User Provider" class.
29+
A default model is provided for you by the `CodeIgniter\Shield\Models\UserModel` class.
4230

43-
```php
44-
public string $userProvider = \App\Models\UserModel::class;
45-
```
31+
You can use your own model to customize user attributes. See [Customizing Shield](./customization.md#custom-user-provider) for details.
4632

4733
## User Identities
4834

docs/customization.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- [Custom Validation Rules](#custom-validation-rules)
1212
- [Registration](#registration)
1313
- [Login](#login)
14+
- [Custom User Provider](#custom-user-provider)
1415

1516
## Route Configuration
1617

@@ -214,3 +215,24 @@ Similar to the process for validation rules in the **Registration** section, you
214215
],
215216
];
216217
```
218+
219+
## Custom User Provider
220+
221+
If you want to customize user attributes, you need to create your own
222+
[User Provider](./concepts.md#user-providers) class.
223+
The only requirement is that your new class MUST extend the provided `CodeIgniter\Shield\Models\UserModel`.
224+
225+
Shield has a CLI command to quickly create a custom `UserModel` class by running the following
226+
command in the terminal:
227+
228+
```console
229+
php spark shield:model UserModel
230+
```
231+
232+
The class name is optional. If none is provided, the generated class name would be `UserModel`.
233+
234+
After creating the class, set the `$userProvider` property in **app/Config/Auth.php** as follows:
235+
236+
```php
237+
public string $userProvider = \App\Models\UserModel::class;
238+
```

0 commit comments

Comments
 (0)