F
Filament14mo ago
KingNii

Select field issue, HELP!!!

For some reason, category_id returns null when I try to save data.
No description
Solution:
Did you do the mount method?
Jump to solution
31 Replies
Thijmen
Thijmen14mo ago
Is it fillable?
KingNii
KingNiiOP14mo ago
Yes it is.
Thijmen
Thijmen14mo ago
I don't see anything wrong in the select So problem must lie somewhere else
KingNii
KingNiiOP14mo ago
Exactly

protected $fillable = [
'name', 'image_url', 'price', 'description','heading', 'stock', 'category_id',
];

protected $fillable = [
'name', 'image_url', 'price', 'description','heading', 'stock', 'category_id',
];
Thijmen
Thijmen14mo ago
Could you see if the select gets outputted right in Filament? You can use $data for that dd() it after saving
KingNii
KingNiiOP14mo ago
Like this?
public function saveProduct()
{
$data = $this->form->getState();

dd($data);
}
public function saveProduct()
{
$data = $this->form->getState();

dd($data);
}
It return null
Thijmen
Thijmen14mo ago
The whole dd or category_id?
KingNii
KingNiiOP14mo ago
Just the category_id
Thijmen
Thijmen14mo ago
Could you set the options manually? With 1 option or so
KingNii
KingNiiOP14mo ago
Let me try it out
Tobias Platen
Tobias Platen14mo ago
try ->default(Insert id of an existing category)
KingNii
KingNiiOP14mo ago
I tried it and it still return null
Select::make('category_id')
->label('Category')
->options([
'1' => 'One',
'2' => 'Two',
])
Select::make('category_id')
->label('Category')
->options([
'1' => 'One',
'2' => 'Two',
])
Thijmen
Thijmen14mo ago
Did you select a value?
KingNii
KingNiiOP14mo ago
Let me try it I did This also returned null
Thijmen
Thijmen14mo ago
The other values of $data are good?
KingNii
KingNiiOP14mo ago
@awcodes Hello 😩
Thijmen
Thijmen14mo ago
Don't tag maintainers No one is obligated to help you
KingNii
KingNiiOP14mo ago
I know. That's why I added the emoji
Thijmen
Thijmen14mo ago
Weird
KingNii
KingNiiOP14mo ago
Thijmen
Thijmen14mo ago
Did you add the category_id to the save function? I noticed now it is a livewire component
KingNii
KingNiiOP14mo ago
Exactly, I'm using form and table builder. I dumped the whole $this->form->getState()
Tobias Platen
Tobias Platen14mo ago
What if you use a TextInput class instead of the Select class and enter the ID as a number there?
KingNii
KingNiiOP14mo ago
Can you give me a code example please? I can't picture what you mean since the categories are being fetched from the database.
Tobias Platen
Tobias Platen14mo ago
TextInput::make('category_id'),
KingNii
KingNiiOP14mo ago
Solved. Issue came from adding searchable() to the Select element
Tobias Platen
Tobias Platen14mo ago
It should also work with searchable().
KingNii
KingNiiOP14mo ago
It should but it's slowing me down at the moment so I'll look into it later
Solution
LeandroFerreira
LeandroFerreira14mo ago
Did you do the mount method?
LeandroFerreira
LeandroFerreira14mo ago
public function mount(): void
{
$this->form->fill();
}
public function mount(): void
{
$this->form->fill();
}
KingNii
KingNiiOP14mo ago
It worked perfectly

Did you find this page helpful?