Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

289
Vistas
How to select or sort using order by array in 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') has values (1,4,2)
  2. When this is selected, the result set for products.id is in order 1,2,4
  3. How to select or order by my session?
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Another way, put this line before your get

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

0

        $arr=[];
        foreach(session("idcompare") as $i){
            foreach($return as $j) {
                if ($i == $j->id) {
                    $arr[] = $j;
                }
            }
        }
        return $arr;
  1. Ohh this is easy
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda