Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
Convierta el resultado elocuente en una matriz asociativa en Laravel

¿Cómo se puede convertir el resultado de matriz elocuente a asociativa? Necesito seleccionar la columna de remolque y tener una como clave y otra como valor. Aquí está el armario que obtuve, sin embargo, el valor es una matriz. Quiero que sea solo la columna "my_value".

 $array = Post::select('my_key','my_value')->get()->keyBy('my_key')
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Debe usar lists (Laravel 5.1) o pluck (Laravel 5.2+):

 $array = Post::lists('my_value', 'my_key');

o

 $array = Post::pluck('my_value', 'my_key');
over 4 years ago · Santiago Trujillo Report

0

Encontré una manera de hacerlo, aunque no estoy seguro de si es la forma adecuada de hacer este rendimiento inteligente ...

 $array = Post::select('my_key','my_value')->get()->mapWithKeys(function ($item) { return [$item['my_key'] => $item['my_value']]; })->toArray();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!