Register
User registration
All routes related to Authentication are placed in routes/auth.php
file, which is loaded inside routes/api.php
.
Registration
For registration in Larafast API Boilerplate responsible app/Http/Controllers/Auth/RegisteredUserController.php
.
The store
method is the primary method in this controller. It handles incoming registration requests. The method accepts a RegisterRequest
object, which encapsulates the validation rules for the registration data.
Here’s a brief overview of the store
method:
The store
method performs the following steps:
-
It creates a new
User
instance using the validated data from theRegisterRequest
object. The password is hashed before being stored in the database. -
It fires a
Registered
event, passing the newly created user as the event’s argument. This event can be used to perform actions after a user has been registered, such as sending a welcome email. -
If roles are implemented in the application, a role can be assigned to the user at this point. This line is commented out in the provided code.
-
Finally, it returns a JSON response containing a token for the newly registered user. This token can be used for subsequent authenticated requests.
To learn more about the return response()->token($user);
method, refer to the Response Macros section.
Remember, this is a basic implementation of a registration controller. Depending on the requirements of your application, you might need to add more functionality, such as email verification, role assignment, etc.
Reference in Postman: Register