Issue with Pivot relation on Repeater

Hello i've been following the steps in the documentation: https://filamentphp.com/docs/3.x/forms/fields/repeater#integrating-with-an-eloquent-relationship In order to save a pivot relationship in a repeater field. However as soon as i add the "->relationship()" chain to the repeater field i get the following error: https://flareapp.io/share/v5pKjbM7 Repeater field code:
Forms\Components\Repeater::make('requestTravellers')
->relationship()
->columnSpanFull()
->reorderable(0)
->addActionLabel('Select another Traveller')
->simple(
Forms\Components\Select::make('traveller_id')
->relationship(
name: 'travellers',
titleAttribute: 'first_name',
modifyQueryUsing: fn(Builder $query) => $query->where('company_id', Auth::user()->company_id)
)
->getOptionLabelFromRecordUsing(fn(Model $record) => "{$record->full_name} | {$record->email}")
->createOptionForm(fn(Form $form) => TravellerResource::form($form))
->required(),
)
->grid(2),
Forms\Components\Repeater::make('requestTravellers')
->relationship()
->columnSpanFull()
->reorderable(0)
->addActionLabel('Select another Traveller')
->simple(
Forms\Components\Select::make('traveller_id')
->relationship(
name: 'travellers',
titleAttribute: 'first_name',
modifyQueryUsing: fn(Builder $query) => $query->where('company_id', Auth::user()->company_id)
)
->getOptionLabelFromRecordUsing(fn(Model $record) => "{$record->full_name} | {$record->email}")
->createOptionForm(fn(Form $form) => TravellerResource::form($form))
->required(),
)
->grid(2),
Let me know if you need any more info and thanks in advance!
Flare
Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given, called in /var/www/html/vendor/filament/forms/src/Components/Select.php on line 769 - The error occurred at http://localhost/requests/create
Solution:
oh the error on the Select component not the repeater do you have the relation travellers in TravellerRequest...
Jump to solution
6 Replies
Lara Zeus
Lara Zeus13mo ago
how your model looks? the relationship must named requestTravellers
AsuranDex
AsuranDexOP13mo ago
It is indeed:
public function requestTravellers(): HasMany
{
return $this->hasMany(TravellerRequest::class);
}
public function requestTravellers(): HasMany
{
return $this->hasMany(TravellerRequest::class);
}
Lara Zeus
Lara Zeus13mo ago
good, also I dont think simple support relation, it's only for flat array
AsuranDex
AsuranDexOP13mo ago
Ok, swapped it to a "normal" repeater:
Forms\Components\Repeater::make('requestTravellers')
->relationship()
->columnSpanFull()
->reorderable(0)
->addActionLabel('Select another Traveller')
->schema([
Forms\Components\Select::make('traveller_id')
->relationship(
name: 'travellers',
titleAttribute: 'first_name',
modifyQueryUsing: fn(Builder $query) => $query->where('company_id', Auth::user()->company_id)
)
->getOptionLabelFromRecordUsing(fn(Model $record) => "{$record->full_name} | {$record->email}")
->createOptionForm(fn(Form $form) => TravellerResource::form($form))
->required(),
])
->grid(2),
Forms\Components\Repeater::make('requestTravellers')
->relationship()
->columnSpanFull()
->reorderable(0)
->addActionLabel('Select another Traveller')
->schema([
Forms\Components\Select::make('traveller_id')
->relationship(
name: 'travellers',
titleAttribute: 'first_name',
modifyQueryUsing: fn(Builder $query) => $query->where('company_id', Auth::user()->company_id)
)
->getOptionLabelFromRecordUsing(fn(Model $record) => "{$record->full_name} | {$record->email}")
->createOptionForm(fn(Form $form) => TravellerResource::form($form))
->required(),
])
->grid(2),
and looks like the same error is thrown: https://flareapp.io/share/OmVwxJ4P
Flare
Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given, called in /var/www/html/vendor/filament/forms/src/Components/Select.php on line 769 - The error occurred at http://localhost/requests/create
Solution
Lara Zeus
Lara Zeus13mo ago
oh the error on the Select component not the repeater do you have the relation travellers in TravellerRequest
AsuranDex
AsuranDexOP13mo ago
AHHH, always a bloody typo xD. I put 'travellers' on the select component and 'traveller' on the pivot model... Thank you, problem solved xD
Want results from more Discord servers?
Add your server