Courses

Livewire 3 From Scratch: Practical Course

New Product Form: Full-Page Component

Summary of this lesson:
- Setting up full-page Livewire component
- Implementing form validation
- Using validation attributes
- Managing form submissions

In this lesson, let's create a second Livewire component for creating a product. We can call this component in two ways.

The first one is the same way as we did with the Products Livewire component making a controller that returns a View and calls the Livewire component. The second one is making the Livewire component a full-page and mapping it directly in the routes file.

This lesson will use the second method, the Livewire component, as a full page.


Creating Livewire Component

So first, we need to create a component.

php artisan make:livewire ProductsCreate

Now we can create a route and map it to this component and add a link to this route.

routes/web.php:

Route::get('products/create', \App\Livewire\ProductsCreate::class)->name('products.create');

resources/livewire/products.blade.php:

<div class="space-y-6">
<div class="flex justify-between">
<div class="space-x-8">
<input wire:model.live="searchQuery" type="search" id="search" placeholder="Search...">
 
<select wire:model.live="searchCategory" name="category">
<option value="0">-- CHOOSE CATEGORY --</option>
@foreach($categories as $id => $category)
<option value="{{ $id }}">{{ $category }}</option>
@endforeach
</select>
</div>
<a wire:navigate href="{{ route('products.create') }}" class="inline-flex items-center px-4 py-2 bg-gray-800 rounded-md font-semibold text-xs text-white uppercase tracking-widest">
Add new product
</a>
</div>
// ...
</div>

add new product button

Now let's add a form and make it work by binding properties and making a method for...

The full lesson is only for Premium Members.
Want to access all 30 lessons of this course? (108 min read)

You also get:

  • 69 courses (majority in latest Laravel 11)
  • Premium tutorials
  • Access to repositories
  • Private Discord