Created
August 24, 2022 18:04
-
-
Save amrikarisma/be74aa0e81aebab08570cda73e02a865 to your computer and use it in GitHub Desktop.
Example scope with lowest price
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function scopeWithPrice($smartphone) | |
{ | |
$queryGetMinPrice = $smartphone->select([ | |
'*', | |
'price' => ProductPrice::select('price')->where('priceable_type', Smartphone::class)->whereColumn('priceable_id', 'smartphones.id')->orderBy('price', 'ASC')->take(1) | |
]); | |
return $queryGetMinPrice; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment