Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

syamimhazmi's avatar

How do I access alias inside multiple select in Db query (closed)

Hello, guys, I have a condition to make inside my query builder. But the problem is how do I access alias that is inside multiple select.

$jobs=DB::table('jobs')
  ->select(DB::raw('jobs.id as id,category.name as cat_name,jobs.name as job_name,jobs.pay_amount,jobs.pay_type,jobs.date_start,jobs.date_end,jobs.time_start,jobs.time_end,location_text,company.company_logo,color,company.company_name,location_gps,
 SUBSTRING_INDEX(location_gps,",",1) as latitude,
 SUBSTRING_INDEX(location_gps,",",-1) as longitude,
 111.111 *
 DEGREES(ACOS(COS(RADIANS((select latitude)))
 * COS(RADIANS('.$lat.'))
 * COS(RADIANS((select longitude) - '.$lng.'))
 + SIN(RADIANS((select latitude)))
 * SIN(RADIANS('.$lat.')))) AS distance'))
  ->join('company','jobs.company_id','=','company.id')
  ->join('category','jobs.category_id','=','category.id')
  ->where('jobs.deleted_at','=',null)
  ->where('jobs.publish','=',1)
  ->where('jobs.name',$conditiom,$clause)
  ->where(DB::raw('select distance'),'<=',$request->distance)
  //->whereRaw('distance <='.$request->distance)
  ->whereIn('jobs.category_id',$allFilter)
  ->orderBy('jobs.id', 'desc')
  ->offset($offset)
  ->limit(10)
  ->get();
0 likes
1 reply

Please or to participate in this conversation.