Concating Fields in Select Option
I need to add the Project Name and IDs to select options. I have used a mutator in the model shown below.
protected function NameAndID(): Attribute
{
return Attribute::make(
get: fn() => $this->ProjectID . ' - ' . $this->ProjectName,
);
}
The NameAndID column works great in the form but not the filters where
SelectFilter::make('PaymentProjectID')->relationship('project', 'NameAndID')->label('Project'),
Gives me
Column not found: 1054 Unknown column 'project.NameAndID' in 'field list'
Any advise gratefully received!
6 Replies
Becase you are expecting a select query to do it opposed to the eloquent attribute.
or
Thanks for the help! I tried that but it's not finding the method. I also tried getOptionLabelUsing as below and it doesn't have an error but still just shows ProjectName in the options
SelectFilter::make('PaymentProjectID')->relationship('project', 'ProjectName')->getOptionLabelUsing(fn($record) => $record->NameAndID)->label('Project'),
Ahh yeah sorry I free handed it. Perfect
Unfortunatey its still just showing the ProjectName' and not the ProjectID. Any thoughts?
Solution
Is the ticket
Genius!! Thanks so much.