Refresh TableRepeater
In a resource, I have a TableRepeater. I want to add an item from a modal, but when I close the modal window, the TableRepeater doesn't refresh.
TableRepeater::make('sedi')
->relationship()
->columns(6)
->live()
->addActionLabel('Aggiungi Sede')
->headers([
Header::make('Nominativo'),
])
->renderHeader(false)
->schema([
Hidden::make('id')
->columnSpan(2),
Hidden::make('ragso1_nome'),
// ->columnSpan(4),
Placeholder::make('codice_ragso1_nome')
->hiddenLabel()
->content(function ($record): string {
return $record?->id.' - '.$record?->ragso1_nome;
}),
])
->addAction(function (Action $action) {
return $action
->form([
Select::make('nominativo')
->preload()
->live()
->options(function (Nominativo $record) {
// dd($record->id);
return Nominativo::whereNull('nominativo_principale_id')
->where('id', '<>', $record->id)
->orderBy('ragso1_nome')
->get()
->mapWithKeys(function ($item) {
return [$item->id => $item->id . ' - ' . $item->ragso1_nome];
});
})
->searchable(),
])
->after(function ($livewire, TableRepeater $component) {
$state = $component->getState();
unset($state[array_key_last($state)]);
})
->before(function (array $data, array $arguments, TableRepeater $component, Nominativo $record_master, $livewire) {
$id_principale = (int) $data['nominativo'];
$nominativo = Nominativo::find($id_principale);
$nominativo->nominativo_principale_id = $record_master->id;
$nominativo->save();
$state = $component->getState();
TableRepeater::make('sedi')
->relationship()
->columns(6)
->live()
->addActionLabel('Aggiungi Sede')
->headers([
Header::make('Nominativo'),
])
->renderHeader(false)
->schema([
Hidden::make('id')
->columnSpan(2),
Hidden::make('ragso1_nome'),
// ->columnSpan(4),
Placeholder::make('codice_ragso1_nome')
->hiddenLabel()
->content(function ($record): string {
return $record?->id.' - '.$record?->ragso1_nome;
}),
])
->addAction(function (Action $action) {
return $action
->form([
Select::make('nominativo')
->preload()
->live()
->options(function (Nominativo $record) {
// dd($record->id);
return Nominativo::whereNull('nominativo_principale_id')
->where('id', '<>', $record->id)
->orderBy('ragso1_nome')
->get()
->mapWithKeys(function ($item) {
return [$item->id => $item->id . ' - ' . $item->ragso1_nome];
});
})
->searchable(),
])
->after(function ($livewire, TableRepeater $component) {
$state = $component->getState();
unset($state[array_key_last($state)]);
})
->before(function (array $data, array $arguments, TableRepeater $component, Nominativo $record_master, $livewire) {
$id_principale = (int) $data['nominativo'];
$nominativo = Nominativo::find($id_principale);
$nominativo->nominativo_principale_id = $record_master->id;
$nominativo->save();
$state = $component->getState();
0 Replies