© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
3 replies
zainalab

Dynamic form for product prices

I want to apply a dynamic form to ProductResource based on the existing license list.

products
- id
- name
products
- id
- name


licenses
- id
- name
licenses
- id
- name

product_price
- id
- license_id
- product_id
- price
- promo_price
product_price
- id
- license_id
- product_id
- price
- promo_price


Table
products
products
hasMany to
product_price
product_price
,
product_price(product_id)
product_price(product_id)
belongsTo to
products
products
, and also
license_id
license_id
belongTo to
licenses
licenses
.

I want to create a form based on a list of
licenses
licenses
by entering
price
price
and
promo_price
promo_price
in the
product_price
product_price
table

I have tried but not achieved

Group::make(function(Livewire $livewire, ?Model $record) {
    if ($livewire instanceof Pages\EditProduct) {
        $productPrices = $record->productPrices;

        return collect($productPrices)->map(function($price) {
            $license = $price->license;

            return Section::make($price->id)
                ->heading(str($license->name)->headline())
                ->id("data.productPrices.record-{$price->id}")
                ->schema([
                    Placeholder::make(json_encode($license)),
                    TextInput::make("record-{$price->id}.price")->numeric()->required(),
                    TextInput::make("record-{$price->id}.promo_price")->numeric()->required(),
                ]);
        })->toArray();
    } elseif ($livewire instanceof Pages\CreateProduct) {
        return collect(License::all())->map(function($license) {
            return Section::make(str($license->name)->headline())
                ->schema([
                    Placeholder::make(json_encode($license)),
                    TextInput::make('productPrices.price')->numeric()->required(),
                    TextInput::make('productPrices.promo_price')->numeric()->required(),
                ]);
        })->toArray();
    } else {
        throw new \InvalidArgumentException('Unsupported $livewire instance.');
    }
})->statePath('productPrices');
Group::make(function(Livewire $livewire, ?Model $record) {
    if ($livewire instanceof Pages\EditProduct) {
        $productPrices = $record->productPrices;

        return collect($productPrices)->map(function($price) {
            $license = $price->license;

            return Section::make($price->id)
                ->heading(str($license->name)->headline())
                ->id("data.productPrices.record-{$price->id}")
                ->schema([
                    Placeholder::make(json_encode($license)),
                    TextInput::make("record-{$price->id}.price")->numeric()->required(),
                    TextInput::make("record-{$price->id}.promo_price")->numeric()->required(),
                ]);
        })->toArray();
    } elseif ($livewire instanceof Pages\CreateProduct) {
        return collect(License::all())->map(function($license) {
            return Section::make(str($license->name)->headline())
                ->schema([
                    Placeholder::make(json_encode($license)),
                    TextInput::make('productPrices.price')->numeric()->required(),
                    TextInput::make('productPrices.promo_price')->numeric()->required(),
                ]);
        })->toArray();
    } else {
        throw new \InvalidArgumentException('Unsupported $livewire instance.');
    }
})->statePath('productPrices');
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

dynamic colspan for resource form
FilamentFFilament / ❓┊help
2y ago
Dynamic Form Component
FilamentFFilament / ❓┊help
2y ago
Dynamic Form Validations
FilamentFFilament / ❓┊help
2y ago
Dynamic Form Field
FilamentFFilament / ❓┊help
3y ago