Skip to content

Commit b6fa2e2

Browse files
committed
feat: add createUserFor docs
1 parent c21f406 commit b6fa2e2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/docs/auth/signup.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,27 @@ $user = auth()->user();
137137

138138
`fromOAuth()` automatically turns off password encoding, so you don't need to worry doing it manually. If you want to turn off password encoding for normal signups, you can find the documentation [here](#password-hashing).
139139

140+
## Signing up another user <Badge type="tip" text="New" />
141+
142+
When building applications that may require you to sign up users on their behalf, for example, an admin signing up a user, you can use the `createUserFor()` method. This method allows you to create a user without needing to log in as the user. It takes in the user's data and returns the auth user instance if the user is saved successfully.
143+
144+
```php
145+
$user = auth()->createUserFor([
146+
'username' => 'example',
147+
'email' => '[email protected]',
148+
'password' => 'password'
149+
]);
150+
151+
if ($user) {
152+
// user is saved
153+
} else {
154+
// user is not saved
155+
$error = auth()->errors();
156+
}
157+
```
158+
159+
It behaves the same way as the `register()` method, except that it doesn't create a session when the user is saved. The user instance returned can be used to perform operations on the user like assigning roles and more.
160+
140161
## Unique fields
141162

142163
There are some fields in your database that should not be repeated for different users. For example, you wouldn't want two users to have the same email address. You can configure Leaf Auth to check for unique fields when a user is being registered:

0 commit comments

Comments
 (0)