From 5020b54de8192ddc4828ae9a0dea172508b73c23 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 9 Dec 2023 07:25:30 +0900 Subject: [PATCH 1/2] docs: add explanations --- .../adding_attributes_to_users.md | 2 + docs/customization/user_provider.md | 38 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/docs/customization/adding_attributes_to_users.md b/docs/customization/adding_attributes_to_users.md index 05530c6f3..83488afd2 100644 --- a/docs/customization/adding_attributes_to_users.md +++ b/docs/customization/adding_attributes_to_users.md @@ -74,6 +74,8 @@ php spark db:table users See [Customizing User Provider](./user_provider.md). +Don't forget to add the added attributes to the `$allowedFields` property. + ## Update Validation Rules You need to update the [validation rules](./validation_rules.md) for registration. diff --git a/docs/customization/user_provider.md b/docs/customization/user_provider.md index 12246043c..2de9345b8 100644 --- a/docs/customization/user_provider.md +++ b/docs/customization/user_provider.md @@ -1,5 +1,7 @@ # Customizing User Provider +## Creating Your Own UserModel + If you want to customize user attributes, you need to create your own [User Provider](../getting_started/concepts.md#user-providers) class. 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 The class name is optional. If none is provided, the generated class name would be `UserModel`. -After creating the class, set the `$userProvider` property in **app/Config/Auth.php** as follows: +## Customizing Your UserModel + +Customize your model as you like. + +If you add attributes, don't forget to add the attributes to the `$allowedFields` +property. + +```php +allowedFields = [ + ...$this->allowedFields, + 'first_name', // Added + 'last_name', // Added + ]; + } +} +``` + +## Configuring to Use Your UserModel + +After creating the class, set your model classname to the `$userProvider` property +in **app/Config/Auth.php**: ```php public string $userProvider = \App\Models\UserModel::class; From 550414b13b73c83b8a698402f7724d5259d8ba59 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 9 Dec 2023 19:13:45 +0900 Subject: [PATCH 2/2] docs: move "Configuring to Use Your UserModel" up --- docs/customization/user_provider.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/customization/user_provider.md b/docs/customization/user_provider.md index 2de9345b8..379574e80 100644 --- a/docs/customization/user_provider.md +++ b/docs/customization/user_provider.md @@ -15,6 +15,15 @@ php spark shield:model UserModel The class name is optional. If none is provided, the generated class name would be `UserModel`. +## Configuring to Use Your UserModel + +After creating the class, set your model classname to the `$userProvider` property +in **app/Config/Auth.php**: + +```php +public string $userProvider = \App\Models\UserModel::class; +``` + ## Customizing Your UserModel Customize your model as you like. @@ -45,12 +54,3 @@ class UserModel extends ShieldUserModel } } ``` - -## Configuring to Use Your UserModel - -After creating the class, set your model classname to the `$userProvider` property -in **app/Config/Auth.php**: - -```php -public string $userProvider = \App\Models\UserModel::class; -```