Odd issue with form select on virtual column
So I have a virtual column in my orders model defined as below:
protected function TitleAndID(): Attribute
{
return Attribute::make(
get: fn() => $this->OrderID . ' - ' . $this->OrderTitle,
);
}
I can access it fine in the in form select shown below
Forms\Components\Select::make('DetailOrderID')->label('Order full')
->options(Order::all()->pluck('TitleAndID', 'OrderID'))
->preload()
->live()
->searchable()
If I try to filter the options then access the TitleAndID column as below I get an error "Unknown column 'TitleAndID' in field list".
What am I missing?
Forms\Components\Select::make('DetailOrderID')
->label('Order')
->options(fn (Get $get): Collection => Order::query()
->where('OrderProjectID', $get('item.ItemProjectID'))
->pluck('TitleAndID', 'OrderID')),
6 Replies
this is an attribute, not virtual column
OK. thanks for that.
Is there a way of defining it where it could be in the filtered set ?
What do you mean? If you use a Virtual Column as mentioned it should work.
Otherwise you need to get the entries from the DB first and then filter the collection, but that's not performant.
Also please read #✅┊rules and check how to format code
Ahh, Thanks so much.
Sorry my misunderstanding. It does work as a virtual column.
Unfortunately, you don't seem to be able to use an Autoincrement column in the virtual column.
Any other thoughts gratefully receoiced!
Hm, feels a bit hacky, but you could update the column manually via Laravels
created()
and updating()
model hookI'll have a go at that. Many thanks.