User Login and Logout Documentation
LoginController
class.
LoginRequest
class, which extends Laravel’s FormRequest
class. The rules
method of this class specifies that both the email
and password
fields are required, and that the email
field must be a valid email address.
store
method in the LoginController
class handles the actual authentication. It retrieves the user record with the provided email address, and then uses Laravel’s Hash
facade to check if the provided password matches the hashed password stored in the database.
If the user record doesn’t exist, or if the password doesn’t match, a ValidationException
is thrown with a message indicating that the authentication failed.
token
macro defined in the ResponseMacroServiceProvider
class. The token is then returned in the response.
destroy
method in the LoginController
class handles logout. It deletes the current access token for the authenticated user, and then returns a success message.
routes/auth.php
file. Both routes use the LoginController
class, and the store
and destroy
methods respectively.