Skip to content

docs: add and use auth()->getProvider()#692

Merged
kenjis merged 4 commits intocodeigniter4:developfrom
kenjis:docs-add-getProvider
Mar 25, 2023
Merged

docs: add and use auth()->getProvider()#692
kenjis merged 4 commits intocodeigniter4:developfrom
kenjis:docs-add-getProvider

Conversation

@kenjis
Copy link
Copy Markdown
Member

@kenjis kenjis commented Mar 25, 2023

If a dev customizes the UserModel and changes the model name, the sample code dose not work.

@kenjis kenjis added the documentation Improvements or additions to documentation label Mar 25, 2023
Copy link
Copy Markdown
Collaborator

@datamweb datamweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a dev customizes the UserModel and changes the model name, the sample code dose not work.

Command php spark shield:model selects the name UserModel by default, if the user uses this command to generate the model, the sample codes should work.

Otherwise, it should apply the following changes.

php spark shield:model KenjiModel
-public string $userProvider = UserModel::class;
+public string $userProvider = \App\Models\KenjiModel::class;
-$users = model('UserModel');
+$users = model('KenjiModel');
$user = $users->findById(1);
$user->fill([
'first_name' => 'kenji', 
'username' =>'kenjis'
]);
$users->save($user, true);
C:\Users\ppars\OneDrive\Desktop\hi>php spark db:table users

CodeIgniter v4.3.2 Command Line Tool - Server Time: 2023-03-25 11:31:53 UTC+00:00

Data of Table "users":

+----+----------+--------+----------------+--------+--------------------+--------------------+--------------------+------------+------------+
| id | username | status | status_message | active | last_active        | created_at         | updated_at         | deleted_at | first_name |
+----+----------+--------+----------------+--------+--------------------+--------------------+--------------------+------------+------------+
| 1  | kenjis   |        |                | 1      | 2023-03-21 16:3... | 2023-03-21 15:3... | 2023-03-25 11:3... |            | kenji      |
+----+----------+--------+----------------+--------+--------------------+--------------------+--------------------+------------+------------+

In any case, using auth()->getProvider() seems good.

@kenjis kenjis merged commit 9d1f6ed into codeigniter4:develop Mar 25, 2023
@kenjis kenjis deleted the docs-add-getProvider branch March 25, 2023 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants