convert mysql query to laravel query builder

\DB::table('cars')
   ->join('garage', 'garage.id', '=', 'cars.garage')       
   ->where('garage.name', 'main')

The above solves the garage and cars part, but you never specified what is aliased to p. If p is a different table then you need to add another call to join() and making the following

 \DB::table('cars')
   ->join('garage', 'garage.id', '=', 'cars.garage')
   //<Other table join goes here for table aliased to p>
   ->where('garage.name', 'main')
   ->select(['p.id', 'p.name', 'p.price'])
   ->get();

Browse More Popular Posts

Leave a Comment