/** * build the free prodcuts tree where parent will be a free product and children are the products list associated. * * @param [array] $select [array to ask for products table field] * @param [integer] $limit [to control the request limit] */ public static function getParentAndChildren($select = ['id', 'description'], $limit = 5) { $events = FreeProduct::select($select)->where('status', '1')->with('orders')->get()->take($limit); $list = []; $events->each(function ($event) use(&$list, $select) { foreach ($select as $value) { $list[$event->id][$value] = $event->{$value}; } $products = FreeProduct::find($event->id)->products->take(6)->toArray(); if ($products) { $list[$event->id]['products'] = $products; } unset($products); }); return $list; }
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); }