F
Filament11mo 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
Thijmen11mo ago
Is it fillable?
KingNii
KingNiiOP11mo ago
Yes it is.
Thijmen
Thijmen11mo ago
I don't see anything wrong in the select So problem must lie somewhere else
KingNii
KingNiiOP11mo 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
Thijmen11mo ago
Could you see if the select gets outputted right in Filament? You can use $data for that dd() it after saving
KingNii
KingNiiOP11mo 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
Thijmen11mo ago
The whole dd or category_id?
KingNii
KingNiiOP11mo ago
Just the category_id
Thijmen
Thijmen11mo ago
Could you set the options manually? With 1 option or so
KingNii
KingNiiOP11mo ago
Let me try it out
Tobias Platen
Tobias Platen11mo ago
try ->default(Insert id of an existing category)
KingNii
KingNiiOP11mo 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
Thijmen11mo ago
Did you select a value?
KingNii
KingNiiOP11mo ago
Let me try it I did This also returned null
Thijmen
Thijmen11mo ago
The other values of $data are good?
KingNii
KingNiiOP11mo ago
@awcodes Hello 😩
Thijmen
Thijmen11mo ago
Don't tag maintainers No one is obligated to help you
KingNii
KingNiiOP11mo ago
I know. That's why I added the emoji
Thijmen
Thijmen11mo ago
Weird
KingNii
KingNiiOP11mo ago
Thijmen
Thijmen11mo ago
Did you add the category_id to the save function? I noticed now it is a livewire component
KingNii
KingNiiOP11mo ago
Exactly, I'm using form and table builder. I dumped the whole $this->form->getState()
Tobias Platen
Tobias Platen11mo ago
What if you use a TextInput class instead of the Select class and enter the ID as a number there?
KingNii
KingNiiOP11mo 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 Platen11mo ago
TextInput::make('category_id'),
KingNii
KingNiiOP11mo ago
Solved. Issue came from adding searchable() to the Select element
Tobias Platen
Tobias Platen11mo ago
It should also work with searchable().
KingNii
KingNiiOP11mo ago
It should but it's slowing me down at the moment so I'll look into it later
Solution
LeandroFerreira
LeandroFerreira11mo ago
Did you do the mount method?
LeandroFerreira
LeandroFerreira11mo ago
public function mount(): void
{
$this->form->fill();
}
public function mount(): void
{
$this->form->fill();
}
KingNii
KingNiiOP11mo ago
It worked perfectly
Want results from more Discord servers?
Add your server