F
Filament17mo ago
oodin53

Problem to attach on relationManager

Hello, I have a problem attaching one model to another with the relationmanager. This is my model : class Competition extends Model { public function squads() { return $this->belongsToMany(Squad::class)->join('clubs', 'club_id', '=', 'clubs.id')->orderBy('clubs.name'); } } class Squad extends Model { public function club() { return $this->belongsTo(Club::class); } } I have a RelationManager : class SquadsRelationManager extends RelationManager { protected static string $relationship = 'squads'; protected static ?string $recordTitleAttribute = 'clubs.name'; public function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('club.name'), ]) } } The club names are displayed correctly on the competition edit page, but when I want to associate a new club, I do a search in the club name list, and I get an error "Undefined property: stdClass::$name". I don't know which "name" property is causing the problem. Is it possible to add it like I did? I'm just starting out with Filament. Thanks for your help. (sorry for my english)
Solution:
Thank you, it's OK with this code : Tables\Actions\AttachAction::make() ->recordSelectSearchColumns(['clubs.name']) ->recordTitle(fn (Squad $record): string => "{$record->club->name} ({$record->id})"),...
Jump to solution
16 Replies
Patrick Boivin
Patrick Boivin17mo ago
I'm not sure but I get a feeling $recordTitleAttribute is causing the issue...
oodin53
oodin53OP17mo ago
Thank you for your answer. In fact, by removing recordTitleAttribute, I no longer get an error and it works, but in the drop-down list for associating a club, I still get "squad" displayed. How can I customize the display of this list to show the club name?
Patrick Boivin
Patrick Boivin17mo ago
Can you share a quick screenshot?
oodin53
oodin53OP17mo ago
I search for "borde" and all the data is displayed. the search is not done.
oodin53
oodin53OP17mo ago
and I would like to search in the relationship ("clubs" table) and not "squads".
Patrick Boivin
Patrick Boivin17mo ago
Just to make sure I understand: this is a Competition resource, and you're attaching some Squad in a relation manager, but you need to show the Club name in the select. Right?
oodin53
oodin53OP17mo ago
yes in my table squad, there is a belongsTo relation to Club
Patrick Boivin
Patrick Boivin17mo ago
Ok... I think you will need to modify the select a little bit, have a look here:
Patrick Boivin
Patrick Boivin17mo ago
And here:
oodin53
oodin53OP17mo ago
i have already Try, but i have an error : Method Filament\Tables\Actions\AttachAction::modifyRecordSelectUsing does not exist.
Patrick Boivin
Patrick Boivin17mo ago
Can you click the SHARE button at the top of the error page? Share the URL with me. Oh ok, I think it's recordSelect() instead of modifyRecordSelectUsing() Maybe the documentation needs to be updated
Solution
oodin53
oodin5317mo ago
Thank you, it's OK with this code : Tables\Actions\AttachAction::make() ->recordSelectSearchColumns(['clubs.name']) ->recordTitle(fn (Squad $record): string => "{$record->club->name} ({$record->id})"),
oodin53
oodin53OP17mo ago
black ka1ser
black ka1ser17mo ago
thank you, this saved my life
Want results from more Discord servers?
Add your server