Select option Concat

I want to show options with item_price and item_number combine like below J94UUdLL-(5000)
Solution:
In options you can return any array/collection so you just need to write your own logic in there to get an array of keys/values as you would any other way in PHP/Laravel. You could use mapWithKeys to achieve this, something like this would work: ```php Select::make('author_id')...
Jump to solution
7 Replies
ConnorHowell
ConnorHowell8mo ago
If you're also likely to use that format elsewhere in your app consider adding a virtual column to the table so you can reference it as if it were a regular column
Yatendra
YatendraOP8mo ago
i want dropdown options. and I don't want by searching.
ConnorHowell
ConnorHowell8mo ago
What does your code currently look like and what have you tried?
Yatendra
YatendraOP8mo ago
Select::make('author_id') ->label('Author') ->options(Lead::all()->pluck('lead_name', 'id')) i want otpions like lead_name-(lead_price)
Solution
ConnorHowell
ConnorHowell8mo ago
In options you can return any array/collection so you just need to write your own logic in there to get an array of keys/values as you would any other way in PHP/Laravel. You could use mapWithKeys to achieve this, something like this would work:
Select::make('author_id')
->label('Author')
->options(Lead::all()->mapWithKeys(function ($lead) {
return [$lead->id => $lead->lead_name.'-('.$lead->lead_price.')'];
}))
Select::make('author_id')
->label('Author')
->options(Lead::all()->mapWithKeys(function ($lead) {
return [$lead->id => $lead->lead_name.'-('.$lead->lead_price.')'];
}))
Yatendra
YatendraOP8mo ago
Working fine Thank You so much
Want results from more Discord servers?
Add your server