multi-select with relationship not returning data

Good afternoon. I'm currently trying to make a Filament action on a livewire page which sends a message to selected users. To select the users I'm using a multi-select. And I added a createOptionForm so a user can add additional users they want to message. This all works wonderful, except when I submit the form the data doesn't to exist (see picture). I don't know if this is a bug in Filament or if I'm doing something wrong. Said select
Forms\Components\Select::make('receivers')
->label('Ontvanger')
->required()
->relationship('receiver', 'email')
->searchable()
->preload()
->multiple()
->options(Auth::user()->contacts()->pluck('email', 'id'))
->createOptionForm([
Hidden::make('owner_id')
->default(Auth::id()),
Hidden::make('owner_type')
->default(User::class),
TextInput::make('name')
->label('Naam')
->required(),
TextInput::make('email')
->required()
->email(),
]),
Forms\Components\Select::make('receivers')
->label('Ontvanger')
->required()
->relationship('receiver', 'email')
->searchable()
->preload()
->multiple()
->options(Auth::user()->contacts()->pluck('email', 'id'))
->createOptionForm([
Hidden::make('owner_id')
->default(Auth::id()),
Hidden::make('owner_type')
->default(User::class),
TextInput::make('name')
->label('Naam')
->required(),
TextInput::make('email')
->required()
->email(),
]),
How I catch the data from the form
->action(function (array $data) {
dd($data);
})
->action(function (array $data) {
dd($data);
})
No description
17 Replies
toeknee
toeknee10mo ago
First thing, remove the the owner_id and owner_type from the form and put it into the mutate Second, closure the options ->options(fn() => Auth::user()->contacts()->pluck('email', 'id')) What does the create option form look like on rendering?
biebthesecond
biebthesecond10mo ago
It just appears as a modal. And when I submit it, it just creates the new model and adds it to the selected options within the multi-select. So it just works as it's supposed to.
No description
biebthesecond
biebthesecond10mo ago
And the main modal / form looks like this. (If that is relevant)
No description
toeknee
toeknee10mo ago
Hang on, where did the DD come from? Tjhe main model form or the creationOptionForm?
biebthesecond
biebthesecond10mo ago
main model form This is the entire Action if that is useful
public function sendMessageAction(): Action
{
return Action::make('sendMessage')
->label('Verstuur bericht')
->form([
Forms\Components\TextInput::make('name')
->label('Onderwerp')
->required(),
Forms\Components\Select::make('receivers')
->label('Ontvanger')
->required()
->relationship('receiver', 'email')
->searchable()
->preload()
->multiple()
->options(Auth::user()->contacts()->pluck('email', 'id'))
->createOptionForm([
Hidden::make('owner_id')
->default(Auth::id()),
Hidden::make('owner_type')
->default(User::class),
TextInput::make('name')
->label('Naam')
->required(),
TextInput::make('email')
->required()
->email(),
]),
Forms\Components\Textarea::make('message')
->label('Bericht'),
Forms\Components\FileUpload::make('files')
->multiple()
->previewable()
->preserveFilenames()
->label('Bestanden')
])
->model(Message::class)
->action(function (array $data) {
dd($data);
app(SaveSentMessage::class)($data);

Notification::make()
->title('Bericht succesvol verstuurd')
->success()
->send();
});
}
public function sendMessageAction(): Action
{
return Action::make('sendMessage')
->label('Verstuur bericht')
->form([
Forms\Components\TextInput::make('name')
->label('Onderwerp')
->required(),
Forms\Components\Select::make('receivers')
->label('Ontvanger')
->required()
->relationship('receiver', 'email')
->searchable()
->preload()
->multiple()
->options(Auth::user()->contacts()->pluck('email', 'id'))
->createOptionForm([
Hidden::make('owner_id')
->default(Auth::id()),
Hidden::make('owner_type')
->default(User::class),
TextInput::make('name')
->label('Naam')
->required(),
TextInput::make('email')
->required()
->email(),
]),
Forms\Components\Textarea::make('message')
->label('Bericht'),
Forms\Components\FileUpload::make('files')
->multiple()
->previewable()
->preserveFilenames()
->label('Bestanden')
])
->model(Message::class)
->action(function (array $data) {
dd($data);
app(SaveSentMessage::class)($data);

Notification::make()
->title('Bericht succesvol verstuurd')
->success()
->send();
});
}
toeknee
toeknee10mo ago
try:
->multiple()
->live()
->multiple()
->live()
biebthesecond
biebthesecond10mo ago
That did not work sadly
toeknee
toeknee10mo ago
Are you fully up to date? If you deselect it then reselect it does it work?
biebthesecond
biebthesecond10mo ago
Are you fully up to date?
I did a composer update right before I send the initial message. Currently on version 3.0.50.
If you deselect it then reselect it does it work?
No, whatever option I choose (even if it's just created) nothing shows up in the dd
No description
toeknee
toeknee10mo ago
strange, I'm not too sure
biebthesecond
biebthesecond10mo ago
Yap, I've been through this with my senior and and he couldn't figure it out either. The strange thing is that when i remove
->multiple()
->multiple()
Or when I remove
->relationship('receiver', 'email')
->searchable()
->preload()
->relationship('receiver', 'email')
->searchable()
->preload()
The data appears again But the relationship is needed for the createOptionForm. And the multiselect is just very user friendly.
toeknee
toeknee10mo ago
And the relationship is a belongsToMany?
biebthesecond
biebthesecond10mo ago
No, a message has one receiver. I just send the same message multiple times to the chosen contacts. This is because how each message is shown somewhere else in the website
public function receiver(): BelongsTo
{
return $this->belongsTo(Contact::class, 'receiver_id', 'id');
}
public function receiver(): BelongsTo
{
return $this->belongsTo(Contact::class, 'receiver_id', 'id');
}
toeknee
toeknee10mo ago
That should be find
biebthesecond
biebthesecond10mo ago
find?
toeknee
toeknee10mo ago
fine*
biebthesecond
biebthesecond10mo ago
this is within the Message model btw. Forgot to mention that, my bad
Want results from more Discord servers?
Add your server
More Posts