Two tables in DB
1:Products
2Prices
Each Product may have multiple prices.
Query in Laravel
$products = DB::table('sets')->join('prices','prices.SetID','sets.id')
->join('setimages','setimages.SetID','sets.id')
->join('setcategories','setcategories.SetID','sets.id')
->orderby('SetPrice','ASC')
->latest('sets.created_at')
->where('setimages.IsDefault',1)
->where('setcategories.CategoryID',$CategoryID)
->select('sets.id as ProductID','sets.SetName','prices.OfferPrice as Discount','setimages.smallImage',DB::raw('MIN(prices.SetPrice) AS SetPrice'))
->groupby('sets.id','sets.SetName','prices.OfferPrice','setimages.smallImage')
->get();
Comments
Post a Comment