getting form data from filament Repeater
Hi everyone, I am using filament repeater and everything is fine when using ->relationship(). The data is updated on edit correctly. But I want to access the information inside repeater forms before saving changes in edit action, and $data shows empty array while I have some data in my repeater. Here's code in edit:
namespace App\Filament\Resources\OrderResource\Pages;
use App\Filament\Resources\OrderResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use App\Models\Order;
use Illuminate\Database\Eloquent\Model;
class EditOrder extends EditRecord
{
protected static string $resource = OrderResource::class;
protected function getHeaderActions(): array
{
return [
// Actions\DeleteAction::make(),
];
}
protected function handleRecordUpdate(Model $record, array $data): Model
{
dd($data);
$record->update($data);
return $record;
}
}
Removing ->relationship() in my resource makes this data accessible through $data when creating new records. But removing ->relationship() causes empty repeater when editing. Any idea of how I can access and modify repeater data inside edit action?2 Replies
Use
->saveRelationshipsUsing(null)
& ->dehydrated(true)
. This would show the repeater $data on both create in handleRecordCreation()
and edit/update in handleRecordUpdate()
. The form will still be filled with your relationship data correctly. Only thing is you would need to manually handle the saving of your relationship data.Is that because you want dynamic options on the form, or dependent on the repeater content, you want to 'edit' the data written back to the database?