Build a Product Booking System with Cart Using Laravel Livewire

Learn how to build a complete Laravel Livewire v3 product booking system with date selection, quantity controls, cart merging, and a real-time sidebar cart. Step-by-step code included.

If you run an online store that sells products requiring date-based booking (for example rental products, events, workshops, or personalized items), then having a dynamic booking form with an integrated cart is essential. In this guide, you will learn how to build a complete Product Booking System + Cart using Laravel Livewire, where users can:

  • Select a product
  • Choose a date (mandatory)
  • Select quantity with + / – controls
  • Add multiple products to a single cart
  • Automatically merge identical items (same product + same date)
  • View the cart in a real-time sidebar

This is a fully working solution you can directly implement in your Laravel application.

Step 1: Update Your Database Structure

Create your products table:

Schema::create('products', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->text('description')->nullable();
    $table->decimal('price', 10, 2);
    $table->timestamps();
});

Step 2: Add Route for Product Details

Add a route to display products page, where we can display cart booking system,

Route::get('/products/{product}', function (\App\Models\Product $product) {
    return view('product-details', compact('product'));
})->name('product.details');

Step 3: Create Cart Service

Create a service app/Services/CartService.php to handle cart related actions from anywhere. This service simplifies the process to handle cart with session.

namespace App\Services;

class CartService
{
    const KEY = 'product_cart';

    public static function all()
    {
        return session()->get(self::KEY, []);
    }

    public static function add($item)
    {
        $cart = self::all();
        $found = false;

        foreach ($cart as &$cartItem) {
            if (
                $cartItem['product_id'] == $item['product_id'] &&
                $cartItem['date'] == $item['date']
            ) {
                $cartItem['quantity'] += $item['quantity'];
                $cartItem['total'] = $cartItem['quantity'] * $cartItem['price'];
                $found = true;
                break;
            }
        }

        if (!$found) {
            $cart[] = $item;
        }

        session()->put(self::KEY, $cart);
    }

    public static function clear()
    {
        session()->forget(self::KEY);
    }
}

This ensures:

  • Users can add multiple different products
  • If a product with the same date already exists → quantities merge

Step 4: Create Livewire Component – Product Booking Form

Create a product booking component using the following artisan command:

php artisan make:livewire BookProductForm

It will create 2 files for product booking,

  • Class File: app/Livewire/BookProductForm.php
  • Blade File: resources/views/livewire/book-product-form.blade.php

Livewire Component Logic

Add the below product booking logic code to the app/Livewire/BookProductForm.php file.

namespace App\Livewire;

use App\Models\Product;
use App\Services\CartService;
use Livewire\Component;

class BookProductForm extends Component
{
    public Product $product;
    public $date;
    public $quantity = 1;

    protected $rules = [
        'date' => 'required|date'
    ];

    public function incrementQty()
    {
        $this->quantity++;
    }

    public function decrementQty()
    {
        if ($this->quantity > 1) {
            $this->quantity--;
        }
    }

    public function bookNow()
    {
        $this->validate();

        CartService::add([
            'product_id' => $this->product->id,
            'name'       => $this->product->name,
            'price'      => $this->product->price,
            'date'       => $this->date,
            'quantity'   => $this->quantity,
            'total'      => $this->quantity * $this->product->price
        ]);

        $this->dispatch('cart-updated');

        $this->reset('date', 'quantity');

        session()->flash('success', 'Product added to cart!');
    }

    public function render()
    {
        return view('livewire.book-product-form');
    }
}

Blade View with Message

Add the following code to the resources/views/livewire/book-product-form.blade.php.

<div class="card p-4 shadow-sm">

    @if(session('success'))
        <div class="alert alert-success">{{ session('success') }}</div>
    @endif

    <h4 class="mb-3">Book: {{ $product->name }}</h4>

    <div class="mb-3">
        <label>Date <span class="text-danger">*</span></label>
        <input type="date" class="form-control" wire:model="date">
        @error('date') <small class="text-danger">{{ $message }}</small> @enderror
    </div>

    <div class="mb-3">
        <label>Quantity</label>
        <div class="input-group" style="width: 150px;">
            <button class="btn btn-outline-secondary" wire:click="decrementQty">-</button>
            <input type="text" class="form-control text-center" wire:model="quantity" readonly>
            <button class="btn btn-outline-secondary" wire:click="incrementQty">+</button>
        </div>
    </div>

    <button class="btn btn-primary w-100" wire:click="bookNow">
        Book Now (₹{{ number_format($product->price, 2) }})
    </button>
</div>

Step 5: Create Livewire Cart Sidebar Component

Cart booking form is ready, but on clicking add to cart button, product is added to the cart. To display this cart, create a cart sidebar livewire component using the below artisan command:

php artisan make:livewire CartSidebar

Component class and blade files will be created as follows,

  • Class File: app/Livewire/CartSidebar.php
  • Blade File: resources/views/livewire/cart-sidebar.blade.php

Livewire Component Logic

Cart sidebar should display all cart products from the cart service. Add the below code to app/Livewire/CartSidebar.php file,

namespace App\Livewire;

use App\Services\CartService;
use Livewire\Component;

class CartSidebar extends Component
{
    protected $listeners = ['cart-updated' => '$refresh'];

    public function render()
    {
        return view('livewire.cart-sidebar', [
            'cart' => CartService::all()
        ]);
    }
}

Blade view with Total Amount

The below code is for resources/views/livewire/cart-sidebar.blade.php file, to display all cart products and the total amount of the cart.

<div class="card p-3 shadow-sm" style="position: sticky; top: 10px;">

    <h5 class="mb-3">Your Cart</h5>

    @if(empty($cart))
        <p>No products in cart.</p>
    @else
        @foreach($cart as $item)
            <div class="border-bottom pb-2 mb-2">
                <strong>{{ $item['name'] }}</strong><br>
                Date: {{ $item['date'] }}<br>
                Qty: {{ $item['quantity'] }}<br>
                <span class="fw-bold">₹{{ $item['total'] }}</span>
            </div>
        @endforeach

        <div class="text-end fw-bold">
            Total: ₹{{ array_sum(array_column($cart, 'total')) }}
        </div>
    @endif
</div>

Step 6: Using Livewire Components

Finally, both of the components are ready. They are ready to be used anywhere. To test, add both these components to product details page as follows,

@extends('layouts.app')

@section('content')
<div class="container py-5">
    <div class="row">

        <div class="col-md-8">
            <h2>{{ $product->name }}</h2>
            <p>{{ $product->description }}</p>
            <p class="fw-bold">Price: ₹{{ number_format($product->price, 2) }}</p>

            <livewire:book-product-form :product="$product" />
        </div>

        <div class="col-md-4">
            <livewire:cart-sidebar />
        </div>

    </div>
</div>
@endsection

Conclusion

You now have a complete Laravel Livewire v3 product booking system with:

✔ Date-based booking
✔ Quantity controls
✔ Real-time sidebar cart
✔ Merging duplicate entries

Can a user add multiple products to the cart?

Yes. Users can add unlimited products, each with separate date and quantity options.

Does the system merge identical cart items?

Yes. If users select the same product with the same date again, quantity is merged.

Is Livewire v3 required?

Yes. This tutorial uses Livewire v3 components, events, and reactive structure.

Can I add checkout or payment later?

Absolutely! This system is designed to extend into a full checkout workflow with payment gateway.

Livewire Event List with Day and Week Filters Using Bootstrap 5

Learn how to build a Laravel Livewire event list with today, next 7 days, and next 30 days filters using Bootstrap 5. Step-by-step tutorial.

Building a dynamic Laravel Livewire event list with date-based filters is a common requirement for dashboards, admin panels, and booking systems.

In this tutorial, you’ll learn how to create a Livewire event list with Today, Next 7 Days, and next 30 Days filters, styled using Bootstrap 5, without page reloads.

Prerequisites

Before starting, make sure you have:

  • Laravel 10+
  • Livewire installed
  • Bootstrap 5 included in your project
  • Basic knowledge of Laravel models and Blade templates

Step 1: Create Events Table

Before building the Livewire component, we need a proper database table to store events. This migration ensures date-based filtering works correctly for today, next 7 days, and next 30 days views.

Run the following artisan command to generate migration:

php artisan make:migration create_events_table

It will create xxxx_xx_xx_xxxxxx_create_events_table.php migration file inside database/migrations folder. Open the generated migration file and update it as follows:

<?php

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

return new class extends Migration {
    public function up(): void
    {
        Schema::create('events', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->text('description')->nullable();
            $table->date('event_date');
            $table->timestamps();

            // Performance optimization for date filtering
            $table->index('event_date');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('events');
    }
};

Execute the migration using:

php artisan migrate

It will create events table in your project database.

Step 2: Create the Livewire Component

Run the following artisan command:

php artisan make:livewire EventList

This will generate following 2 files:

  • app/Livewire/EventList.php
  • resources/views/livewire/event-list.blade.php

Step 3: Livewire Component Logic

Open app/Livewire/EventList.php and add the following code:

<?php

namespace App\Livewire;

use Livewire\Component;
use App\Models\Event;

class EventList extends Component
{
    public string $mode = 'month'; // month | week | day

    public function mount()
    {
        $this->mode = 'month';
    }

    public function showMonth()
    {
        $this->mode = 'month';
    }

    public function showWeek()
    {
        $this->mode = 'week';
    }

    public function showDay()
    {
        $this->mode = 'day';
    }

    public function getEventsProperty()
    {
        return match ($this->mode) {

            // Today only
            'day' => Event::whereDate('event_date', today())
                ->orderBy('event_date')
                ->get(),

            // Next 7 days (today + next 6 days)
            'week' => Event::whereDate('event_date', '>=', today())
                ->whereDate('event_date', '<=', today()->copy()->addDays(6))
                ->orderBy('event_date')
                ->get(),

            // Last 30 days (default)
            default => Event::whereDate('event_date', '<=', today()->addDays(30))
                ->orderBy('event_date')
                ->get(),
        };
    }

    public function render()
    {
        return view('livewire.event-list');
    }
}

Why We Use whereDate()

  • Prevents time-related filtering bugs
  • Works correctly for both DATE and DATETIME
  • Avoids issues where week filters accidentally show all events

Step 4: Blade View Using Bootstrap 5

Add following code to resources/views/livewire/event-list.blade.php :

<div>

    <!-- Filter Buttons -->
    <div class="btn-group mb-3" role="group">
        <button
            wire:click="showMonth"
            class="btn {{ $mode === 'month' ? 'btn-primary' : 'btn-outline-primary' }}">
            Next 30 Days
        </button>

        <button
            wire:click="showWeek"
            class="btn {{ $mode === 'week' ? 'btn-primary' : 'btn-outline-primary' }}">
            Next 7 Days
        </button>

        <button
            wire:click="showDay"
            class="btn {{ $mode === 'day' ? 'btn-primary' : 'btn-outline-primary' }}">
            Today
        </button>
    </div>

    <!-- Events List -->
    <div class="card">
        <div class="list-group list-group-flush">
            @forelse ($this->events as $event)
                <div class="list-group-item">
                    <div class="d-flex justify-content-between align-items-center">
                        <h6 class="mb-1">{{ $event->title }}</h6>
                        <small class="text-muted">
                            {{ \Carbon\Carbon::parse($event->event_date)->format('d M Y') }}
                        </small>
                    </div>

                    @if($event->description)
                        <p class="mb-0 text-muted small">
                            {{ $event->description }}
                        </p>
                    @endif
                </div>
            @empty
                <div class="list-group-item text-center text-muted py-4">
                    No events found
                </div>
            @endforelse
        </div>
    </div>

</div>

Step 5: Use the Component

To add the Livewire component, add the following code anywhere in your Blade file:

<livewire:event-list />

Final Result

  • Loads next 30 days by default
  • Shows today’s events instantly
  • Displays next 7 days events correctly
  • No page reloads
  • Clean Bootstrap UI

Conclusion

This Livewire + Bootstrap solution is perfect for dashboards, admin panels, and public event listings. It’s easy to extend with pagination, previous/next navigation, or even a calendar view.

Laravel Livewire Day-Wise Schedule Viewer with Bootstrap 5

Learn how to build a day-wise schedule viewer in Laravel Livewire using Bootstrap 5. Includes migration, seeder, navigation buttons, and UX best practices.

Managing schedules by day is a common requirement in admin dashboards, booking systems, internal tools, and SaaS applications. In this tutorial, you’ll learn how to build a day-wise schedule viewer using Laravel Livewire, styled with Bootstrap 5, and powered by weekday-based database records.

This guide covers everything from database migration and seeding to Livewire navigation logic and UX improvements.

What You’ll Learn in This Tutorial

  • How to store weekday-based schedules in Laravel
  • Build a Livewire component to show schedules dynamically
  • Navigate schedules using Previous / Next buttons
  • Disable invalid navigation (like going before today)
  • Seed realistic day-wise data (max 6 events per day)
  • Create a Bootstrap 5 UI without JavaScript

Tech stack used

  • Laravel 10+
  • Livewire 3
  • Bootstrap 5
  • Carbon (Date handling)
  • MySQL / MariaDB

Database Migration

Before creating the model, seeder, and Livewire component, we need a database table to store weekday-based schedules.

Each record represents one event for a specific weekday (Monday–Sunday).

Create Migration

To create a migration file, run the following command,

php artisan make:migration create_weekday_schedules_table

It will create a migration file named xxxx_xx_xx_create_weekday_schedules_table.php in the database/migrations folder.

Migration File

Open the migration file and add the following code into it,

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('weekday_schedules', function (Blueprint $table) {
            $table->id();

            // 1 = Monday, 7 = Sunday (ISO-8601)
            $table->unsignedTinyInteger('weekday')->index();

            $table->string('title');
            $table->time('start_time');
            $table->time('end_time');
            $table->text('description')->nullable();

            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('weekday_schedules');
    }
};

Now, this migration file is ready to be run.

Run Migration

Run the migration using the following artisan command,

php artisan migrate

Eloquent Model

Now, create a model for weekday schedules table, created by the migration. To create an eloquent model, run the following command,

php artisan make:model WeekdaySchedule

It will create a model file named WeekdaySchedule.php inside app/Models folder. Open that model file and add the following code in the file,

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class WeekdaySchedule extends Model
{
    protected $fillable = [
        'weekday',
        'title',
        'start_time',
        'end_time',
        'description',
    ];
}

Database migration and models files are ready. It is time to create a livewire component for day-wise schedule.

Livewire Component

Livewire components can be easily created using the artisan livewire command as follows,

php artisan make:livewire DaySchedule

This command will create two files as follows,

  • Component file named DaySchedule.php inside app/Livewire folder,
  • Component view blade file named day-schedule.blade.php inside resources/views/livewire folder.

Open the DaySchedule.php file and add the following code into it,

namespace App\Livewire;

use Livewire\Component;
use Carbon\Carbon;
use App\Models\WeekdaySchedule;

class DaySchedule extends Component
{
    public Carbon $currentDate;

    public function mount()
    {
        $this->currentDate = now();
    }

    public function previousDay()
    {
        if ($this->currentDate->isToday()) {
            return;
        }

        $this->currentDate = $this->currentDate->copy()->subDay();
    }

    public function nextDay()
    {
        $this->currentDate = $this->currentDate->copy()->addDay();
    }

    public function getSchedulesProperty()
    {
        return WeekdaySchedule::where(
            'weekday',
            $this->currentDate->dayOfWeekIso
        )->get();
    }

    public function render()
    {
        return view('livewire.day-schedule');
    }
}

And open the component view file to add the following code,

<div class="card shadow-sm">

    <div class="card-header d-flex justify-content-between align-items-center">

        <button
            wire:click="previousDay"
            class="btn btn-outline-secondary btn-sm"
            @if($currentDate->isToday()) disabled @endif
        >
            ← Previous
        </button>

        <h5 class="mb-0 fw-semibold">
            {{ $currentDate->format('l, d M Y') }}
        </h5>

        <button
            wire:click="nextDay"
            class="btn btn-outline-secondary btn-sm"
        >
            Next →
        </button>

    </div>

    <div class="card-body">
        @forelse ($this->schedules as $schedule)
            <div class="border rounded p-3 mb-3">
                <div class="d-flex justify-content-between">
                    <strong>{{ $schedule->title }}</strong>
                    <span class="badge bg-primary">
                        {{ $schedule->start_time }} – {{ $schedule->end_time }}
                    </span>
                </div>

                @if($schedule->description)
                    <small class="text-muted d-block mt-1">
                        {{ $schedule->description }}
                    </small>
                @endif
            </div>
        @empty
            <div class="alert alert-light text-center mb-0">
                No schedule available for this day.
            </div>
        @endforelse
    </div>

</div>

This component is now ready. But, we don’t have any data to display. So, for data, create a seeder.

Daywise Seeder

Create a seeder using the following artisan command,

php artisan make:seeder WeekdayScheduleSeeder

This will create a file inside database/seeders folder named as WeekdayScheduleSeeder.php.

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\WeekdaySchedule;

class WeekdayScheduleSeeder extends Seeder
{
    public function run(): void
    {
        $weeklyData = [
            1 => [
                ['Standup Meeting', '09:00', '09:15', 'Daily sync'],
                ['Development', '09:30', '12:30', 'Feature work'],
                ['Lunch', '12:30', '13:30', 'Break'],
                ['Code Review', '13:30', '15:00', 'Review PRs'],
                ['Client Call', '15:15', '16:00', 'Client discussion'],
                ['Wrap Up', '16:15', '17:00', 'Day end'],
            ],
            2 => [
                ['Standup', '09:00', '09:15', 'Team sync'],
                ['Development', '09:30', '12:30', 'Coding'],
                ['Learning', '13:30', '14:30', 'Upskilling'],
                ['Bug Fixing', '14:30', '16:00', 'Fix issues'],
            ],
            7 => [
                ['Off Day', '00:00', '23:59', 'No work scheduled'],
            ],
        ];

        foreach ($weeklyData as $weekday => $events) {
            foreach (array_slice($events, 0, 6) as $event) {
                WeekdaySchedule::create([
                    'weekday' => $weekday,
                    'title' => $event[0],
                    'start_time' => $event[1],
                    'end_time' => $event[2],
                    'description' => $event[3],
                ]);
            }
        }
    }
}

Run seeder using the following command,

php artisan db:seed --class=WeekdayScheduleSeeder

With component code and some data, it is now ready to be display on any page. To attach this livewire component, use the following code,

<livewire:day-schedule />

Final Results

  • Users see today’s schedule by default
  • Can navigate future days using Next
  • Previous button is disabled on today
  • Clean Bootstrap UI
  • Fully reactive Livewire experience
  • Easily extendable for Filament or APIs

Conclusion

This approach provides a clean, scalable way to manage day-wise schedules in Laravel using Livewire and Bootstrap 5. It avoids JavaScript complexity, keeps logic server-driven, and delivers a smooth UX.

If you’re building dashboards, booking systems, or internal tools — this pattern fits perfectly.

How I Built a Full File Explorer in Laravel Livewire with Search

Learn how to create a complete file explorer in Laravel using Livewire and Bootstrap – with folders, subfolders, and document search. Step-by-step tutorial with code.

Have you ever wanted to give your Laravel app a professional, desktop-like file explorer – with folders, nested subfolders and document search?

In this tutorial, I’ll walk you through building full file explorer using Laravel Livewire and Bootstrap 5. We’ll create a clean two-pane layout: the left sidebar displays your folder structure (applications and subfolders), while the right pane dynamically lists documents with instant search and filtering.

By the end, you’ll have a fully functional, real-time file manager where users can browse folders, search documents by name and group them by type – all powered by Livewire’s reactivity and Laravel’s filesystem magic.

What We’re Building

We’ll create a two-pane interface like a typical file explorer:

  • Left sidebar → list of applications/folders and nested subfolders.
  • Right pane → list of documents for the selected application.
  • Features:
    • Real-time search
    • Subfolder navigation
    • Document type–based organization

Step 1. Setting Up the Database

We’ll use two tables: applications and documents. applications table holds our folders and subfolders, while documents table holds all documents with name and path with application relation.

Schema::create('applications', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->foreignId('parent_id')->nullable()->constrained('applications')->cascadeOnDelete();
    $table->timestamps();
});

Schema::create('documents', function (Blueprint $table) {
    $table->id();
    $table->foreignId('application_id')->constrained()->cascadeOnDelete();
    $table->string('title');
    $table->string('file_path');  // e.g. "documents/report.pdf"
    $table->string('type')->nullable(); // e.g. "invoice", "report", "letter"
    $table->timestamps();
});

Step 2. Eloquent Relationships

Define relationships in models as follows,

// Application.php
class Application extends Model
{
    protected $fillable = ['name', 'parent_id'];

    public function parent()
    {
        return $this->belongsTo(Application::class, 'parent_id');
    }

    public function children()
    {
        return $this->hasMany(Application::class, 'parent_id');
    }

    public function documents()
    {
        return $this->hasMany(Document::class);
    }
}

// Document.php
class Document extends Model
{
    protected $fillable = ['application_id', 'title', 'file_path', 'type'];

    public function application()
    {
        return $this->belongsTo(Application::class);
    }
}

Step 3. The Livewire Component

Run the following command to create the livewire component:

php artisan make:livewire ApplicationExplorer

It will create 2 files as follows,

  • app/Http/Livewire/ApplicationExplorer.php for file explorer processing.
  • resources/views/livewire/application-explorer.blade.php for file explorer view.

Define all Processes

Open app/Http/Livewire/ApplicationExplorer.php and add the following code:

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Application;
use App\Models\Document;
use Livewire\WithPagination;
use Illuminate\Support\Facades\Storage;
use ZipArchive;

class ApplicationExplorer extends Component
{
    use WithPagination;
    protected $paginationTheme = 'bootstrap';

    public $selectedAppId = null;
    public $search = '';
    public $filterType = '';

    public function updatingSearch()
    {
        $this->resetPage();
    }

    public function selectApp($appId)
    {
        $this->selectedAppId = $appId;
        $this->reset(['search', 'filterType']);
        $this->resetPage();
    }

    public function render()
    {
        $applications = Application::with('children')->whereNull('parent_id')->get();

        $selectedApp = $this->selectedAppId ? Application::find($this->selectedAppId) : null;

        $documents = collect();
        if ($selectedApp) {
            $documents = Document::where('application_id', $this->selectedAppId)
                ->when($this->filterType, fn($q) => $q->where('type', $this->filterType))
                ->when($this->search, fn($q) => $q->where('title', 'like', "%{$this->search}%"))
                ->paginate(10);
        }

        return view('livewire.application-explorer', [
            'applications' => $applications,
            'selectedApp'  => $selectedApp,
            'documents'    => $documents,
        ]);
    }
}

Update the View

To update the view, open resources/views/livewire/application-explorer.blade.php and add the below code,

<div class="container-fluid vh-100">
    <div class="row h-100">
        {{-- Sidebar --}}
        <div class="col-3 border-end bg-light p-0 overflow-auto">
            <div class="p-3 border-bottom"><h5 class="mb-0">Applications</h5></div>
            <ul class="list-group list-group-flush">
                @foreach($applications as $app)
                    @include('livewire.partials.sidebar-app', ['app' => $app, 'level' => 0])
                @endforeach
            </ul>
        </div>

        {{-- Right Pane --}}
        <div class="col-9 p-4">
            @if($selectedApp)
                <div class="d-flex justify-content-between align-items-center mb-3">
                    <h4 class="mb-0">Documents in "{{ $selectedApp->name }}"</h4>
                    <div class="d-flex gap-2 align-items-center" style="width:50%;">
                        <select class="form-select w-auto" wire:model="filterType">
                            <option value="">All Types</option>
                            <option value="invoice">Invoice</option>
                            <option value="report">Report</option>
                            <option value="letter">Letter</option>
                        </select>
                        <input type="text" class="form-control" placeholder="Search..." wire:model.debounce.300ms="search">
                    </div>
                </div>

                @if($documents->count())
                    <div class="table-responsive">
                        <table class="table table-striped table-bordered align-middle">
                            <thead class="table-dark">
                                <tr>
                                    <th>#</th>
                                    <th>Document</th>
                                    <th>Type</th>
                                    <th>Created</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($documents as $i => $doc)
                                    <tr>
                                        <td>{{ $i + 1 }}</td>
                                        <td>📄 {{ $doc->title }}</td>
                                        <td>{{ $doc->type ?? '-' }}</td>
                                        <td>{{ $doc->created_at->format('d M Y') }}</td>
                                        <td><button class="btn btn-sm btn-primary">View</button></td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>

                    {{ $documents->links() }}
                @else
                    <div class="text-muted fst-italic">No documents found.</div>
                @endif
            @else
                <div class="text-muted fst-italic">Select an application to view documents.</div>
            @endif
        </div>
    </div>
</div>

For sidebar, create a new file at resources/views/livewire/partials/sidebar-app.blade.php and add the following code,

<li class="list-group-item p-0 d-flex justify-content-between align-items-center">
    <button wire:click="selectApp({{ $app->id }})"
            class="btn flex-grow-1 text-start px-3 py-2 {{ $selectedAppId === $app->id ? 'btn-secondary' : 'btn-light' }}"
            style="padding-left: {{ 12 + ($level * 15) }}px;">
        📁 <span class="ms-2">{{ $app->name }}</span>
    </button>
</li>

@if($app->children->count())
    <ul class="list-group list-group-flush">
        @foreach($app->children as $child)
            @include('livewire.partials.sidebar-app', ['app' => $child, 'level' => $level + 1])
        @endforeach
    </ul>
@endif

Step 4. File Storage Notes

Documents are uploaded to storage/app/public/documents/.... So, make sure that your public link exists:

php artisan storage:link

Always use:

Storage::disk('public')->exists($path);
Storage::disk('public')->path($path);

This ensures correct behavior since your files are under the public disk.

Step 5. Directory Structure by Document Type

When uploading new documents, if you want to make a directory structure based on document types, you can follow this approach:

$file->store("documents/{$applicationId}/" . strtolower($type), 'public');

This automatically creates folders like:

/storage/app/public/documents/3/invoices/file.pdf

Final Result

  • Left Sidebar: Displays all applications + nested subfolders.
  • Right Pane: Shows searchable, paginated, filterable document table.

Conclusion

And there you have it – a complete file explorer built with Laravel Livewire, featuring a responsive sidebar, real-time search and type-based organization.

This approach not only showcases the power of Livewire for dynamic interfaces but also demonstrates how easily Laravel’s Storage, and Eloquent relationships can come together to create a feature-rich, production-ready document management system.

From here, you can take it even further – add drag-and-drop uploads, access control, file previews, download all files in single zip with complete folder structure or even integrate third-party storage like AWS S3. With this foundation, your Laravel app can handle documents as efficiently as any modern file manager.

How to Use TinyMCE with Livewire and Sortable.js in a Dynamic Form Builder

Learn how to integrate TinyMCE with Livewire and Sortable.js in a dynamic form builder. Build interactive forms with drag-and-drop and rich text editing in Laravel.

When building a drag-and-drop form builder with Laravel Livewire, a common challenge is integrating rich text editors like TinyMCE while also supporting sortable components and repeaters.

Checkout my article to build dynamic form builder using Laravel Livewire here.

This guide walks you through a working setup where:

  • Components can be added dynamically.
  • Fields can include TinyMCE editors.
  • Components can be dragged and reordered using Sortable.js.
  • TinyMCE properly initializes and syncs data back to Livewire.

Step 1: Create Your TinyMCE Field Partial

Inside your Blade view for form fields, create a partial for TinyMCE:

<div wire:ignore>
    <textarea
        id="{{ $editorId }}"
        class="tinymce"
        data-model="{{ $modelPath }}"
    >{{ is_string($value) ? $value : '' }}</textarea>
</div>
  • wire:ignore ensures Livewire doesn’t overwrite the editor.
  • data-model stores the Livewire binding path for syncing.

Step 2: Add TinyMCE + Sortable.js JavaScript

Include TinyMCE and Sortable.js in your layout:

<script src="https://cdn.tiny.cloud/1/no-api-key/tinymce/6/tinymce.min.js" referrerpolicy="origin"></script>
<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script>

Now initialize editors and handle drag-and-drop:

<script>
    function initTinyMCEEditors() {
        document.querySelectorAll('textarea.tinymce').forEach((el) => {
            if (!el.id || tinymce.get(el.id)) return;

            tinymce.init({
                selector: `#${el.id}`,
                menubar: false,
                plugins: 'link lists code image table',
                toolbar: 'undo redo | bold italic underline | alignleft aligncenter alignright | bullist numlist | link image code',
                setup: function (editor) {
                    editor.on('init', () => {
                        editor.setContent(el.value || '');
                    });
                    editor.on('Change KeyUp', () => {
                        const model = el.dataset.model;
                        if (model) {
                            Livewire.dispatch('input', { name: model, value: editor.getContent() });
                        }
                    });
                }
            });
        });
    }

    function destroyTinyMCEEditors() {
        document.querySelectorAll('textarea.tinymce').forEach((el) => {
            const editor = tinymce.get(el.id);
            if (editor) {
                editor.destroy();
            }
        });
    }

    function syncAllTinyMCEDataToLivewire() {
        document.querySelectorAll('textarea.tinymce').forEach((el) => {
            const editor = tinymce.get(el.id);
            if (editor) {
                const model = el.dataset.model;
                if (model) {
                    Livewire.dispatch('input', { name: model, value: editor.getContent() });
                }
            }
        });
    }

    document.addEventListener('DOMContentLoaded', function () {
        const el = document.getElementById('components-sortable');

        if (el) {
            new Sortable(el, {
                animation: 150,
                handle: '.drag-handle',
                onStart: destroyTinyMCEEditors,
                onEnd: () => {
                    setTimeout(() => {
                        Livewire.dispatch('reorderUpdated');
                        initTinyMCEEditors();
                    }, 100);
                }
            });
        }

        initTinyMCEEditors();
        Livewire.hook('message.processed', initTinyMCEEditors);
    });
</script>

Step 3: Sortable Container Blade Example

<ul id="components-sortable">
    @foreach ($components as $index => $component)
        <li class="component-item">
            <div class="drag-handle cursor-move">⠿</div>

            @include('form-fields', [
                'fields' => $component['fields'],
                'modelPath' => "components.{$index}.fields"
            ])
        </li>
    @endforeach
</ul>

Step 4: Sync TinyMCE Data Before Save

Since TinyMCE keeps data internally, Livewire won’t automatically have the latest content.

Fix this by syncing before save:

<button type="button" onclick="syncAllTinyMCEDataToLivewire(); Livewire.find('{{ $this->id }}').save()">Save</button>

And in your Livewire component:

protected $listeners = ['save-form' => 'save'];

public function save()
{
    // At this point, TinyMCE data is synced
}

Conclusion

Integrating TinyMCE with Livewire and Sortable.js in a dynamic form builder may seem complex at first, but once set up correctly, it opens up powerful possibilities for building highly interactive and user-friendly applications. By combining the real-time reactivity of Livewire, the drag-and-drop flexibility of Sortable.js, and the rich editing features of TinyMCE, you can create a seamless experience where users can easily manage, reorder, and edit dynamic content without page reloads.

This approach not only improves usability but also ensures that your forms remain scalable and maintainable as your project grows. With the right configuration and careful handling of event updates, you’ll have a robust solution ready for production.