Filament Relation Manager - Form Not Updating

Hi, I have a Filament Relation Manager and it's working well for the table part, but the form isn't updating in the browser. For example, the form function is as below:
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('user_id')
->multiple()
->preload()
->relationship('mustReadUsers', 'name')
->searchable(),
Forms\Components\TextInput::make('test')
->label('New field'),
]);
}
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('user_id')
->multiple()
->preload()
->relationship('mustReadUsers', 'name')
->searchable(),
Forms\Components\TextInput::make('test')
->label('New field'),
]);
}
However, this isn't reflected in the browser. Can someone offer some insight to why? I'm guessing the form may be being defined elsewhere instead but I have no idea where to start looking.
Solution:
try $table->recordTitleAttribute('name')
Jump to solution
31 Replies
Expecto Patronum
Have you tried to refresh the browser again after updating the data ?
Hightower
HightowerOP7mo ago
Yeah, tried migrate:fresh and cache:clear too
Hightower
HightowerOP7mo ago
The modal looks like this:
No description
Hightower
HightowerOP7mo ago
So I can attach users, but as you can see the name isn't showing and the additional test field is missing too, so I'm wondering where the actual displayed form is being defined if not in the relation manager. I tried a dd() in the form before the return too, and it didn't run so makes it look like it's not getting to the Form function in the relation manager
Expecto Patronum
Can you share the file here ? Easy for debugging
Hightower
HightowerOP7mo ago
Let me know if you need other files
Hightower
HightowerOP7mo ago
So I've found out how to do it with the ->form() function But that's not how I want / would expect to have to do it Sorry, when I say I can do it through the form() method, I can get the extra field etc but the relationship bit isn't working Feel like I'm quite close but oh so far
Expecto Patronum
Can you show the model ?
Hightower
HightowerOP7mo ago
I'm getting a much different error now:
Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given, called in /home/kmo/axis/vendor/filament/forms/src/Components/Select.php on line 762
Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given, called in /home/kmo/axis/vendor/filament/forms/src/Components/Select.php on line 762
Expecto Patronum
If you using a many to many . Probably you can change ->form(function (AttachAction $action) { dd(print_r($this->mustReadUsers(), true)); return [ Forms\Components\Select::make('user_id') ->label('User') ->relationship('mustReadUsers', 'name') ->multiple() ->preload() ->searchable(), ]; }), ]) to ->authorize(true) only because attachfunction will take the record through mustReadUser relationship . You can try this first
Hightower
HightowerOP7mo ago
This change sets it back to before, where the form function isn't being reached and just get a standard form like this:
Hightower
HightowerOP7mo ago
No description
Hightower
HightowerOP7mo ago
Relationships all work great in Tinker So the models must be fine. I think I'm missing something in my RelationManager Probably that my table is not named in the standard convention? But I think I've done that properly at least as far as I can tell
Expecto Patronum
Your model so far is good But may i know . What form do you want to do ? Because . If you just want to attach the record . Thats how to do it Else
Expecto Patronum
You can try add $action->getRecordSelect()
Hightower
HightowerOP7mo ago
I suppose the issue is then it's showing 'user' in list of users when attaching Instead of the actually name
Hightower
HightowerOP7mo ago
No description
Dan Harrin
Dan Harrin7mo ago
Can you explain why you're overriding the entire form()? maybe i missed it, its a long thread
Hightower
HightowerOP7mo ago
Hi Dan, I was overriding the form to try and figure out why it's showing 'user' instead of 'Mr User' in the above modal Sorry, it has gotten a little long winded as I've gone round in circles with this, but I think I just need to figure out how to tell it I want the user's name in the select box rather than 'user'
Dan Harrin
Dan Harrin7mo ago
please remove that override, that select will be using the "record title attribute" from the relation manager which is not defined
Solution
Dan Harrin
Dan Harrin7mo ago
try $table->recordTitleAttribute('name')
Hightower
HightowerOP7mo ago
Think I've got it
Expecto Patronum
Yes
Hightower
HightowerOP7mo ago
Yeah, that has worked - so simple when you know where to look!
Expecto Patronum
Agreed with dan I missed it tol
Dan Harrin
Dan Harrin7mo ago
that should be in the default relation manager stub so not sure why its not there for you
Expecto Patronum
Too
Dan Harrin
Dan Harrin7mo ago
the reason why its showing "user" is because we generate a default title from the model name if you dont have a record title attribute defined
Hightower
HightowerOP7mo ago
I may have deleted it not knowing what it was doing, so probably my mistake That's awesome, appreciate your support on this and helping me get there.
Want results from more Discord servers?
Add your server