У меня есть компонент Livewire OpportunityQuote, в структуре которого есть Repeater, например:
Код: Выделить всё
class OpportunityQuote extends Component implements HasForms
{
use InteractsWithForms, CanGenerateUuids;
public $quote_services = [];
public function mount()
{
$this->quote_services = [];
$this->form->fill([
'quote_services_repeater' => $this->quote_services,
]);
}
public function form(Form $form): Form
{
return $form
->schema([
Repeater::make('quote_services_repeater')
->label('Serviços Adicionados')
->itemLabel(function (array $state) {
return new HtmlString(
view('filament.components.service-repeater-item')
->with('state', $state)
->render()
);
})
->schema(function (array $state) {
return [
// Livewire::make(OpportunityQuoteItem::class, [
// 'item' => $state
// ]),
TextInput::make('name')
->email()
->label('Email'),
];
})
->columns(4)
->defaultItems(1)
->collapsible()
->collapsed()
->orderable(false)
->addable(false)
])->statePath('quote_services');
}
public function onAddedService($item, $index)
{
$uuid = $this->generateUuid();
$this->quote_services['quote_services_repeater'][$uuid] = $item;
$this->form->fill([
'quote_services_repeater' => $this->quote_services['quote_services_repeater'],
]);
}
Код: Выделить всё
class OpportunityQuoteItem extends Component
{
public ?array $item = [];
public function mount($item)
{
$this->item = $item;
}
public function render()
{
return view('livewire.opportunity.quote-item');
}
}
Если мы посмотрим на метод itemLabel, то увидим, что по умолчанию он имеет $state, который представляет текущую строку, поэтому вы можете настроить заголовок.
Но, В методе схемы переменная $state представляет не просто строку, а состояние повторителя в целом, являясь многомерным массивом.
Но как мне это сделать?
Подробнее здесь: https://stackoverflow.com/questions/791 ... -component
Мобильная версия