Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Im trying to pluck more than one value in PHP Filament v3

I am trying to pluck more than one value. I want firstname and lastname. How do i get both values to show up.

    SelectFilter::make('participant_id')
                    ->attribute('participant_id')
                    ->label(__('messages.participant_model_firstname'))
                    ->options([
                        array_unique(
                            Participant::all()
                                ->pluck('firstname', 'id')
                                ->toArray()
                        )
                    ]),
                

I found nothing really interesting on the internet to solve this problem.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

first of all, don’t call all() unless you want to return everything from the database, instead call pluck() on the eloquent query builder so that only the name and id columns are loaded, saving memory and cpu processing.

Create a new column fullname by joining firstname and lastname:

Participant::query()
  ->select([
    DB::raw("CONCAT(firstname, ' ', lastname) as fullname"),
    'id',
  ])
  ->pluck('fullname', 'id')
  ->toArray()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading