[WIP] Add thumb on offers, refactor categories, try to fix counter on relations polymorphic with eage loader, bad pattern !
This commit is contained in:
@@ -6,17 +6,42 @@ use App\Models\Shop\Offer;
|
||||
|
||||
class Offers
|
||||
{
|
||||
|
||||
public static function getThumbSrcById($id)
|
||||
{
|
||||
return self::getThumbSrc(self::get($id));
|
||||
}
|
||||
|
||||
public static function getThumbSrc(Offer $offer)
|
||||
{
|
||||
return Articles::getThumbSrc($offer->article->image);
|
||||
}
|
||||
|
||||
public static function getLast()
|
||||
{
|
||||
return Offer::with(['article.image'])->orderByDesc('updated_at')->get();
|
||||
}
|
||||
|
||||
|
||||
public static function getByCategoryWithTags($category_id)
|
||||
{
|
||||
$category = Categories::get($category_id);
|
||||
$tags = Categories::getTagsByCategory($category);
|
||||
$offers1 = self::getByCategory($category_id)->toArray();
|
||||
$offers2 = self::getByTags($tags)->toArray();
|
||||
$data = array_merge($offers1, $offers2);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
return Offer::with(['article.image'])->byCategory($category_id)->get();
|
||||
}
|
||||
|
||||
public static function getByTags($tags)
|
||||
{
|
||||
return Offer::with(['article.tags'])->byTags($tags)->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Offer::orderBy('value', 'asc')->get();
|
||||
|
||||
Reference in New Issue
Block a user