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

292
Views
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 answers
Answer question

0

Another way, put this line before your get

->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. Ohh this is easy
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!