EXAMPLES
Base CSS themes Bootstrap Material Design Filled Material Design Outlined Floating Navbars, Sidebars & Footers All 74 SPA layouts AJAX Requests File uploads User account Authentication forms Roles & Permissions

Authentication Forms
Authentication Forms

All of Laravel's default authentication forms can be written as single class Komposers.

The main goal of this tutorial is to show how to handle submits with special behavior beyond simple CRUD operations.

Authentication forms are the ideal candidates for that since they require hashing, session handling, events triggering, etc...

Default Login Form

This login form uses Laravel's default `AuthenticateUsers` Trait. The handle method calls the login method from that trait to authenticate the user.

You may also define the `$redirectTo` property for redirecting the user after a successful login as you would have done in the LoginController.

Regarding the authorization, we just need to make sure that only guests can submit the form. As for the display authorization, that should be handled in our route middleware.

Default Registration Form

We are showing two ways of registering here:

  • The first is the default Laravel registration form.
  • The other (see comments) shows how to also create a unique username for a registered user.

Here we connect the User Eloquent class since we are creating a User record in the database. The form will handle saving the attributes automatically (even hashing the password). The only thing we still need to add is some functionality after having saved the model. You will notice that the `completed` method will:

  • Fire an `Illuminate\Auth\Events\Registered` event.
  • And log the current user in

You may also define the `$redirectTo` property for redirecting the user after a successful login as you would have done in the RegisterController.

Regarding the authorization, we just need to make sure that only guests can submit the form. As for the display authorization, that should be handled in our route middleware.

Forgot Password Form

Reset Password Form

Logout Form

Similarly to Laravel's default logout process, we create a form that consists of a simple button or link that submits (by POST request) to the `logout` route, which in turn takes care of cleaning up the user's session in our backend.

We may also use the `$redirectTo` property to indicate where to redirect the user after a successful logout.

If you are building a multi-language site and wish to preserve the language even after logout, you may keep the session's locale in memory and re-assign it after regenerating it as shown in the commented portion of the code.

Demo