Dynamic form for product prices
I want to apply a dynamic form to ProductResource based on the existing license list.
Table
I want to create a form based on a list of
I have tried but not achieved
products
- id
- nameproducts
- id
- namelicenses
- id
- namelicenses
- id
- nameproduct_price
- id
- license_id
- product_id
- price
- promo_priceproduct_price
- id
- license_id
- product_id
- price
- promo_priceTable
productsproducts hasMany to product_priceproduct_price, product_price(product_id)product_price(product_id) belongsTo to productsproducts, and also license_idlicense_id belongTo to licenseslicenses.I want to create a form based on a list of
licenseslicenses by entering priceprice and promo_pricepromo_price in the product_priceproduct_price tableI 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');