Skip to content

Commit 9d1f6ed

Browse files
authored
Merge pull request #692 from kenjis/docs-add-getProvider
docs: add and use auth()->getProvider()
2 parents 917bade + da6e3cc commit 9d1f6ed

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

docs/authentication.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public $defaultAuthenticator = 'session';
5050
## Auth Helper
5151

5252
The auth functionality is designed to be used with the `auth_helper` that comes with Shield. This
53-
helper method provides the `auth()` command which returns a convenient interface to the most frequently
53+
helper method provides the `auth()` function which returns a convenient interface to the most frequently
5454
used functionality within the auth libraries.
5555

5656
```php
@@ -61,6 +61,9 @@ auth()->user();
6161
auth()->id();
6262
// or
6363
user_id();
64+
65+
// get the User Provider (UserModel by default)
66+
auth()->getProvider();
6467
```
6568

6669
> **Note**

docs/quickstart.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ By default, the only values stored in the users table is the username. The first
271271
```php
272272
use CodeIgniter\Shield\Entities\User;
273273

274-
$users = model('UserModel');
274+
// Get the User Provider (UserModel by default)
275+
$users = auth()->getProvider();
276+
275277
$user = new User([
276278
'username' => 'foo-bar',
277279
'email' => 'foo.bar@example.com',
@@ -291,7 +293,9 @@ $users->addToDefaultGroup($user);
291293
A user's data can be spread over a few different tables so you might be concerned about how to delete all of the user's data from the system. This is handled automatically at the database level for all information that Shield knows about, through the `onCascade` settings of the table's foreign keys. You can delete a user like any other entity.
292294

293295
```php
294-
$users = model('UserModel');
296+
// Get the User Provider (UserModel by default)
297+
$users = auth()->getProvider();
298+
295299
$users->delete($user->id, true);
296300
```
297301

@@ -302,9 +306,10 @@ $users->delete($user->id, true);
302306
The `UserModel::save()`, `update()` and `insert()` methods have been modified to ensure that an email or password previously set on the `User` entity will be automatically updated in the correct `UserIdentity` record.
303307

304308
```php
305-
$users = model('UserModel');
306-
$user = $users->findById(123);
309+
// Get the User Provider (UserModel by default)
310+
$users = auth()->getProvider();
307311

312+
$user = $users->findById(123);
308313
$user->fill([
309314
'username' => 'JoeSmith111',
310315
'email' => 'joe.smith@example.com',

0 commit comments

Comments
 (0)