How to access parent record inside repeater field?

I have a Repeater with relationship inside Form, i want to validate the item inside repeater using unique validation, what i need is the id from parent, but i cant get that record. Here's the fields :
[
TextInput::make('name')
->required(),
Repeater::make('details')
->relationship()
->schema([
Grid::make()
->schema([
Select::make('category_id')
->relationship('category', 'name')
->unique(ignoreRecord: true, modifyRuleUsing: function(Unique $rule, Get $get, $record){
// $record result is the record from current item, not parent item
// I need a $parent to validate that this item is unique by parent_id, type_id, and category_id columns
return $rule->where('type_id', $get('type_id'))->where('parent_id', $parent->getKey());
})
->required(),
Select::make('type_id')
->relationship('type', 'name')
->required(),
TextInput::make('fee')
->numeric()
->required(),
]),
])
]
[
TextInput::make('name')
->required(),
Repeater::make('details')
->relationship()
->schema([
Grid::make()
->schema([
Select::make('category_id')
->relationship('category', 'name')
->unique(ignoreRecord: true, modifyRuleUsing: function(Unique $rule, Get $get, $record){
// $record result is the record from current item, not parent item
// I need a $parent to validate that this item is unique by parent_id, type_id, and category_id columns
return $rule->where('type_id', $get('type_id'))->where('parent_id', $parent->getKey());
})
->required(),
Select::make('type_id')
->relationship('type', 'name')
->required(),
TextInput::make('fee')
->numeric()
->required(),
]),
])
]
2 Replies
Dennis Koch
Dennis Koch8mo ago
Try fn ($livewire) => $livewire->record
lucianosnchz
lucianosnchz8mo ago
Hello, did you find a solution?