Laravel: Adding the form at the bottom of the list

Now I want to do something. On http://127.0.0.1:8000/newdog we still got the “add dog” form. But I want to add it at the bottom of this list.

How do we do that? Using subviews.

Using the @include directive we can include a view within another view.

So let’s include the “new dog form” in the dogs.blade.php template:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        @vite('resources/css/app.css')
    </head>
    <body class="p-4">
        <h1 class="font-bold border-b-gray-300 border-b pb-2 mb-3">
            Dogs
        </h1>
        <ul>
            @foreach ($dogs as $dog)
                <li>{{ $dog->name }}</li>
            @endforeach
        </ul>
        @include('newdog')
    </body>
</html>

It works!

But now since we use Tailwind, the form looks different than the “standalone” route to add a new dog:

Let’s style it a bit:

<form method="post" action="{{ route('dog.new') }}">
    @csrf
    <h3 class="font-bold border-b-gray-300 border-b pb-2 mb-3 mt-4">
    Add a new dog
    </h3>
    <label>Name</label>
    <input type="text" name="name" id="name" class="border border-gray-200 p-1">
    <input type="submit" name="send" value="Submit" class="bg-gray-200 p-1 cursor-pointer border border-black">
</form>

Here’s the result:

Now, we don’t want the form to have its own route any more, because we have it on /.

So let’s create a folder named partials in resources/views and move the file resources/views/newdog.blade.php to resources/views/partials/form.blade.php

In resources/views/dogs.blade.php change

@include('newdog')

to

@include('partials.form')

and in routes/web.php you can now delete the GET route that showed that form on /newdog:

Route::get('/newdog', function () {
    return view('newdog');
});

Lessons in this unit:

0: Introduction
1: Getting started
2: Blade
3: Dynamic routes
4: Adding a database
5: How to use migrations to create and modify the database schema
6: Using forms to accept user input and store it into the database
7: Adding a better layout
8: ▶︎ Adding the form at the bottom of the list
9: Allow users to delete dogs from the list
10: Adding authentication using Laravel Breeze
11: Only authenticated users can add items to the database
12: Push the app code to GitHub
13: Deployment
14: Dynamic routes advanced
15: Non-web routes
16: Creating commands

Join my AI Workshop!

The Web Development BOOTCAMP cohort starts in February 2026