Laravel 9 Add/Remove Multiple Input Fields Dynamically with jQuery

As a developer, we work with form fields to get the values from the user to show or store the information.

But, wait, have you ever dealt with the situation where you have to give authority to the user to create multiple input fields dynamically.

If you are a laravel developer and want to integrate similar functionality in laravel.

In this comprehensive tutorial, we will tell you how to eloquently and dynamically add and remove multiple form input fields in Laravel using the notable JavaScript jQuery library.

After integrating dynamic input fields in laravel, you will easily add or remove multiple or more than one input field in the laravel app, which will utterly help your users share extra information.

To create dynamic input fields, we will use popular Bootstrap 5 CSS library; the Bootstrap 5 make our job facile in adding and removing input field element from design outlook.

How to Create Multiple Add/Remove Input Fields Feature in Laravel 9

  • Step 1: Download Laravel Project
  • Step 2: Connect to Database
  • Step 3: Setup Migration & Model
  • Step 4: Create Contact Controller
  • Step 5: Register New Routes
  • Step 6: Create Blade View
  • Step 7: View Application in Browser

Download Laravel Project

To add/remove multiple input fields dynamically with jQuery in laravel, start downloading a new app.

composer create-project --prefer-dist laravel/laravel laravel_star-trek

Connect to Database

Connect laravel application to the database by adding database details in .env file.


Setup Migration & Model

Next, run command to create new migration and model file.

php artisan make:model Contact -m

Add the table value which will store the dynamic input field’s values in database/migrations/create_contacts_table.php.


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateContactsTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('contacts', function (Blueprint $table) {

     * Reverse the migrations.
     * @return void
    public function down()

Likewise, add the table value into the app/Models/Contact.php file.


namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Contact extends Model
    use HasFactory;
    protected $fillable = [

Without further ado, execute the command to invoke the migration, after which you may see the new table created in the database.

php artisan migrate

Create Contact Controller

Furthermore, you require a separate controller, where you can define the code to validate the multiple input values and store the values in the database.

php artisan make:controller ContactController

In this section, you will have to head over to app\Http\Controllers\ContactController.php file and place the provided code into the file.


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Contact;

class ContactController extends Controller
    public function index() 
        return view("contact");

    public function submitForm(Request $request)
            'multiInput.*.subject' => 'required'
        foreach ($request->multiInput as $key => $value) {
        return back()->with('success', 'Form has been submitted.');

Register New Routes

Controller logic doesn’t work unless it is connected to route, consequently create few new routes in routes/web.php file.


use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ContactController;

Route::get('/contact', [ContactController::class, 'index']);
Route::post('/add-multi-values', [ContactController::class, 'submitForm']);

Create Blade View

In the last section, we will conjugate the whole code to define multiple input fields, get into the resources/views folder, create a new contact.blade.php file and then add the provided code in resources/views/contact.blade.php file.

<!DOCTYPE html>

    <meta charset="utf-8">
    <title>Laravel Multi Add and Remove Input Fields Example</title>
    <link href="" rel="stylesheet">

    <div class="container mt-5">
        <form method="POST" action="{{ url('add-multi-values') }}">
            @if ($errors->any())
            <div class="alert alert-warning">
                    @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
            @if (Session::has('success'))
            <div class="alert alert-info">
                <p>{{ Session::get('success') }}</p>
            <table class="table" id="multiForm">
                    <th>Add Hobbies</th>
                    <td><input type="text" name="multiInput[0][hobbies]" class="form-control"/></td>
                    <td><input type="button" name="add" value="Add" id="addRemoveIp" class="btn btn-outline-dark"></td>

            <div class="d-grid mt-3">
              <input type="submit" class="btn btn-dark btn-block" value="Submit">

<script src=""></script>
    var i = 0;
    $("#addRemoveIp").click(function () {
        $("#multiForm").append('<tr><td><input type="text" name="multiInput['+i+'][hobbies]" class="form-control" /></td><td><button type="button" class="remove-item btn btn-danger">Delete</button></td></tr>');
    $(document).on('click', '.remove-item', function () {

View App in Browser

So, far we have described everything eloquently, now; to commemorate the functionality, we will start the laravel project and view the app in the browser using the given url.

php artisan serve

Javascript add multiple input fields dynamically in laravel


Throughout this intense guide, we focused on explaining things with precision. We shared practical methods to persuade how to add multiple input fields in laravel eloquently.

We took the help of the jQuery library. Apart from that, we told you how to validate multiple input fields in laravel.

We created a simple form and displayed multi form input fields in rows with input fields. To design the dynamic add and remove input fields, we used the Bootstrap 5 library.