Professional Documents
Culture Documents
Customize Laravel Jetstream (Registration and Login) - DeV Community
Customize Laravel Jetstream (Registration and Login) - DeV Community
23 5
Hello, welcome back to my series, previously, I wrote on how to Customize Laravel Auth
(Laravel Breeze Registration and Login), this is for those that use Laravel breeze for
Authentification, but some of my readers who used Laravel Jetstream are still finding it
difficult to customize the Registration and Login process in order to suit their needs.
For those that did not read the previous article, what we are trying to achieve is to
customize the Registration and Login whereby a developer can choose to use
username and password for login different from the default email and password, this
is because some of the users of your application might not be having email address, so
the person might use username for the registration and be using it for login.
without further ado, let's dive into the stuff of the day, if you read Customize Laravel
Auth (Laravel Breeze Registration and Login), most of the steps are similar.
return User::create([
'firstname' => $input['firstname'],
'lastname' => $input['lastname'],
'username' => $input['username'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
}
In the validate( ) method, I removed email, and added firstname, lastname and
username. Also in the User::create, I added the new fields.
Step 3: Add the new fields and modify the name field
We are going to modify the existing name field with firstname and also add other fields,
but to modify an existing fields, we need a package doctrine/dbal, The Doctrine DBAL
library is used to determine the current state of the column and to create the SQL
queries needed to make the requested changes to your column. Laravel docs
composer update
Then add the following fields to the up( ) method of the migration file created above
You will notice how we are going to rename our name field to firstname and added
lastname and username, we made the username to be unique() and also modify email
from mandatory to nullable().
Database
<x-guest-layout>
<x-jet-authentication-card>
<x-slot name="logo">
<x-jet-authentication-card-logo />
</x-slot>
<div>
<x-jet-label value="{{ __('First Name') }}" />
<x-jet-input class="block mt-1 w-full" type="text" name="firstname
</div>
<div>
<x-jet-label value="{{ __('Last Name') }}" />
<x-jet-input class="block mt-1 w-full" type="text" name="lastname"
</div>
<div>
<x-jet-label value="{{ __('Username') }}" />
<x-jet-input class="block mt-1 w-full" type="text" name="username"
</div>
<div class="mt-4">
<x-jet-label value="{{ __('Email') }}" />
<x-jet-input class="block mt-1 w-full" type="email" name="email" :v
</div>
<div class="mt-4">
<x-jet-label value="{{ __('Password') }}" />
<x-jet-input class="block mt-1 w-full" type="password" name="passwo
</div>
<div class="mt-4">
<x-jet-label value="{{ __('Confirm Password') }}" />
<x-jet-input class="block mt-1 w-full" type="password" name="passwo
</div>
<x-jet-button class="ml-4">
{{ __('Register') }}
</x-jet-button>
</div>
</form>
</x-jet-authentication-card>
</x-guest-layout>
<x-guest-layout>
<x-jet-authentication-card>
<x-slot name="logo">
<x-jet-authentication-card-logo />
</x-slot>
@if (session('status'))
<div class="mb-4 font-medium text-sm text-green-600">
{{ session('status') }}
</div>
@endif
<form method="POST" action="{{ route('login') }}">
@csrf
<div>
<x-jet-label value="{{ __('Username') }}" />
<x-jet-input class="block mt-1 w-full" type="text" name="username"
</div>
<div class="mt-4">
<x-jet-label value="{{ __('Password') }}" />
<x-jet-input class="block mt-1 w-full" type="password" name="passwo
</div>
<x-jet-button class="ml-4">
{{ __('Login') }}
</x-jet-button>
</div>
</form>
</x-jet-authentication-card>
</x-guest-layout>
I slightly got overwhelmed with the changes of laravel 8 esp with laravel
jetstream. That’s why I prefer the laravel breeze which is simpler. The simpler
the better. But I’m glad that someone wrote about jetstream. Given the overall
complexity that jetstream add to the laravel project, I think it’s worth to try and
explore.
Bro... this is an amazing and clear tutorial. Best I've seen in a long time. Thanks
a lot!
yamin • 8 abr 21
sir , can you make a tutorial for multiplle authentication in laravel jetstream
bro could you please help me how to add nav menu and use your layout ?
and please help me how to add some logic to call specific model in controller
dashboard?
Thanks before, this is exactly what i need. But, I got error, where is
LoginHistory class?
djcorea • 28 feb 21
Sentry PROMOTED
Try Sentry
Kingsconsult
I am Kingsley Okpara, a Python and PHP Fullstack Web developer and tech writer, I also have extensive
knowledge and experience with JavaScript while working on applications developed with VueJs.
LOCATION
Lagos, Nigeria
EDUCATION
Bsc.ed Mathematics, Enugu State University of Science and Technology, Enugu, Nigeria
WORK
Mid-level Web Developer at Plexada-Si
JOINED
4 ago 2019
FusionAuth PROMOTED
Learn more