Including all hops by weight

3 years ago

jaseofspades88

This seems to work....

Code

$quote = App\Pricing\Models\ClientQuote::cachedByWeightForRoute(
    5,
    'US',
    'GR'
)->first();

return $quote->hops->flatMap->packages
    ->filter(function ($package) {
        return $package->weight === 5;
    })

    ->flatMap->charges->sum('amount');

Output

=> 10895
Video course: PHP Package Development