Courses

Livewire 3 From Scratch: Practical Course

Parent-Children Form

You're reading a FREE PREVIEW of a PREMIUM course.
Summary of this lesson:
- Setting up product order structure
- Managing dynamic form fields array
- Implementing add/remove product functionality
- Handling nested data submission

The second demo project out of four is a parent-children form. It's a typical form, for example, for invoices or orders with products.

In this form, we will be able to add products to the list or remove them from a list.

parent children product form


DB Structure

First, let's quickly see what the Migration and Model look like.

database/migrations/xxx_create_products_table.php:

Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->integer('price');
$table->timestamps();
});

app/Models/Product.php:

use Illuminate\Database\Eloquent\Casts\Attribute;
 
class Product extends Model
{
protected $fillable = [
'name',
'price',
];
 
protected function price(): Attribute
{
return Attribute::make(
get: fn($value) => $value / 100,
set: fn($value) => $value * 100,
);
}
}

And a seeder to have some products:

Product::create(['name' => 'iPhone', 'price' => 999.99]);
Product::create(['name' => 'iPad', 'price' => 699.99]);
Product::create(['name' => 'iMac', 'price' => 1999.99]);

Livewire Component

Now let's create a Livewire component.

php artisan make:livewire ParentChildren

Next, let's think about what properties we will need. Obviously, for customer name and email. Then we will need one for all the products, which will be a collection. And lastly, we will need a property to store...

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

You also get:

  • 76 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord