Customize Laravel Registration Form With Additional Fields

Jun 01

Hey Guys! This is Aman. Hope you all are doing well. Hope you all read my last blog which was of the Laravel Authorization. In that blog, we learned how to work with Laravel Auth package and how to make Login, Registration, Forgot Password, etc. Now, Let’s continue with the Laravel Auth and proceed further with the registration form customization with additional fields.

As you have seen the default registration form Laravel provides us in my last blog. It just has Name, E-Mail Address, Password and Confirm Password.

Sometimes we required some other fields in the form like Phone Number, Address, Gender, Date of Birth and so on.

Let’s start the development with the registration form customization with a new field. I am going to create Phone Number.

Step 1: First make a migration to create a new field in the database table. Command will be like.

Now, you can see in the database->migrations we have a newly migrated migration file.

Step 2: Open the file in the editor and modify the up() and down() functions. It will look like this.

Step 3: After that, run the migration by following the command.

This migration will create a new field in the database.

Step 4: Go to resources/auth/register.blade.php and edit the registration form by adding the below HTML code.

Tada!! We can see a new field in the registration form.

Step 5: Oh my God! Another step 🙄. Yes, it is required. Because it will save the phone number in the database. Don’t worry it is not that difficult 😁

Open RegisterController.php controller found in app/Http/Controllers/Auth, and modify the validator. It will look like this.

After this, scroll down in the same file and modify the create function. It will look like

Step 6: This is the final step. Save the RegisterController.php file open app/User.php and add ‘phone’ field in the $fillable property and save the file.

That’s it. Now, test the registration form you can see the saved number field in the database.

Yeah!!! It is done. Well done 👍 Now, enjoy the work you have done and follow the same steps if you need more fields in the form.

Try these steps and make the Customization working in your Laravel application form 😎👍

I created one sample Laravel application. You can visit my repo and fork it or clone the code from my repo and start work further. Click here to visit my GitHub repo.

This is all about Customize Laravel Registration Form With Additional Fields. If you found this article useful please clap 👏 for this article.

Have a happy coding! 🤗

Leave a Reply

Your email address will not be published.