Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions docs/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This document covers some of the base concepts used throughout the library.

Shield is designed so that the initial setup of your application can all happen in code with nothing required to be
saved in the database. This means you do not have to create large seeder files that need to run within each environment.

Instead, it can be placed under version control, though the Settings library allows those settings to be easily stored
in the database if you create an interface for the user to update those settings.

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

## User Providers

You can use your own models to handle user persistence. Shield calls this the "User Provider" class.
A default model is provided for you by the `CodeIgniter\Shield\Models\UserModel` class. You can change
this in the `Config\Auth::$userProvider` setting. The only requirement is that your new class
MUST extend the provided `UserModel`.

Shield has a CLI command to quickly create a custom `UserModel` class by running the following
command in the terminal:

```console
php spark shield:model UserModel
```

The class name is optional. If none is provided, the generated class name would be `UserModel`.

You should set `Config\Auth::$userProvider` as follows:
Shield has a model to handle user persistence. Shield calls this the "User Provider" class.
A default model is provided for you by the `CodeIgniter\Shield\Models\UserModel` class.

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

## User Identities

Expand Down
22 changes: 22 additions & 0 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [Custom Validation Rules](#custom-validation-rules)
- [Registration](#registration)
- [Login](#login)
- [Custom User Provider](#custom-user-provider)

## Route Configuration

Expand Down Expand Up @@ -181,3 +182,24 @@ Similar to the process for validation rules in the **Registration** section, you
],
];
```

## Custom User Provider

If you want to customize user attributes, you need to create your own
[User Provider](./concepts.md#user-providers) class.
The only requirement is that your new class MUST extend the provided `CodeIgniter\Shield\Models\UserModel`.

Shield has a CLI command to quickly create a custom `UserModel` class by running the following
command in the terminal:

```console
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:

```php
public string $userProvider = \App\Models\UserModel::class;
```