app\FreeProduct::getWithProducts PHP Method

getWithProducts() public static method

Returns all products contained in the orders associated with a freeproduct.
public static getWithProducts ( Illuminate\Database\Eloquent\Collection $items ) : freeproducts
$items Illuminate\Database\Eloquent\Collection
return freeproducts collection of all the products contained in the orders associated with freeproduct, but defined as a property of the model
    public static function getWithProducts(Collection $items)
    {
        $freeproducts = $items->each(function ($item, $key) {
            $list_products_orders = Collection::make();
            foreach ($item->orders as $order) {
                $list_products_orders = $list_products_orders->merge($order->products);
            }
            $item->products = $list_products_orders;
        });
        return $freeproducts;
    }

Usage Example

コード例 #1
0
ファイル: FreeProduct.php プロジェクト: masterpowers/antVel
 public static function getNextEvents($fields = ['*'], $limit = 5, $date)
 {
     $events = FreeProduct::select($fields)->OfStatus('1')->IsValidIn($date)->with('orders')->orderBy('draw_date')->take($limit)->get();
     return FreeProduct::getWithProducts($events);
 }