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

290
Views
Cómo seleccionar u ordenar usando order by array en Laravel
$return=DB::table('products') ->select('products.*', 'images.address') ->leftJoin("images",function($join){ $join->on('products.id', '=', 'images.product_id'); $join->where('images.default','1'); }) ->whereIn('products.id',session("idcompare")) ->get();
  1. session('idcompare') tiene valores (1,4,2)
  2. Cuando se selecciona esto, el conjunto de resultados para products.id está en orden 1,2,4
  3. ¿Cómo seleccionar u ordenar por mi sesión?
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

De otra manera, ponga esta línea antes de obtener

 ->orderByRaw('FIELD(products.id,session("idcompare"))')
over 4 years ago · Santiago Trujillo Report

0

 $arr=[]; foreach(session("idcompare") as $i){ foreach($return as $j) { if ($i == $j->id) { $arr[] = $j; } } } return $arr;
  1. Oh, esto es fácil
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!