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>

Now let's add a form and make it work by binding properties and making a method for...
ProductsCreate.php should inherit:
use Livewire\Attributes\Rule;Thanks
I guess there might be a mistake. The file name below routes/web.php showed: resources/livewire/products-create.blade.php, which cantains 'Add new product' button. I guess this file should be: resources/livewire/products.blade.php
There are two code blocks with the heading
resources/livewire/products-create.blade.php:but the first one should actually beresources/livewire/products.blade.php:Thanks.
If someone got this error "SQLSTATE[HY000]: General error: 1364 Field 'category_id' doesn't have a default value".
you just need to add the "category_id" to your Product Model filable array;
protected $fillable = [ 'name', 'description', 'category_id', ];
For those that have the exception below:
Livewire page component layout view not found: [components.layouts.app]You need to create the the directory config/livewire.php with this code below:
Config files should be published not created manually
Also, you should first check the 6th lesson https://laraveldaily.com/lesson/livewire-3/full-page-components-replace-laravel-controllers
You're right, thanks, I ran the command to publish
php artisan livewire:publish --config.