I started building a web application using Laravel 8. I have noticed that quite a lot of things have changed in Laravel 8 including authentication. Now, I am trying to use Jetstream for auth.
I have run the following command to integrate it into the application.
composer require laravel/jetstream
php artisan jetstream:install inertia
npm install && npm run dev
When I go to the /register
route, I can see the registration form with name, email, password and password confirmation fields. What I would like to do is that I would like to add another field called, "company" and I would like to apply custom validation rules to it.
I found on the Jetstream documentation that I could customise the authentication process in the boot method of the JetstreamServiceProvider class as follow.
Fortify::authenticateUsing(function (Request $request) {
});
But it does not apply to register. How can I customise the registration process adding new fields and applying custom validation rules?
Firstly, you should add the
company
field to the user table using the migration found indatabase\migrations\2014_10_12_000000_create_users_table.php
.Then run this command
php artisan migrate:fresh
to migrate your new users table.Then add the field to the fillable array inside the
User
model found in\app\Models\User.php
like so:And now you can find the registration view under
resources\views\auth\register.blade.php
then you can duplicate an input block to use it for the'company'
field.Then you can do the validation in this class:
app\Actions\Fortify\CreateNewUser.php
Then, you are ready.