[WIP] Add thumb on offers, refactor categories, try to fix counter on relations polymorphic with eage loader, bad pattern !

This commit is contained in:
Ludovic CANDELLIER
2021-12-17 00:30:07 +01:00
parent 2be07ce72c
commit a3c6fc6ebe
26 changed files with 171 additions and 107 deletions

View File

@@ -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();