Skip to content

Instantly share code, notes, and snippets.

@introqt
Created July 29, 2020 09:15
Show Gist options
  • Save introqt/078c8701b38d7434e1ed980887b1b425 to your computer and use it in GitHub Desktop.
Save introqt/078c8701b38d7434e1ed980887b1b425 to your computer and use it in GitHub Desktop.

Revisions

  1. introqt created this gist Jul 29, 2020.
    64 changes: 64 additions & 0 deletions HomePage.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    <?php

    declare(strict_types=1);

    namespace Modules\Home\Services;

    use App\Core\Enums\BaseEnum;
    use Illuminate\Database\Eloquent\Collection;

    use Modules\Home\Entities\ArticleOnMain;
    use Modules\Home\Entities\ProductCategoryOnMain;
    use Modules\Home\Entities\SeasonalOffer;
    use Modules\Home\Entities\Slider;

    use App\Models\Page;

    /**
    * Class HomePage
    * @package Modules\Home\Services
    */
    class HomePage implements HomePageInterface
    {
    /**
    * @return Collection|SeasonalOffer[]
    */
    public function getSeasonalOffers(): Collection
    {
    return SeasonalOffer::active()->with('product.products')->get();
    }

    /**
    * @return Collection|ArticleOnMain[]
    */
    public function getArticles(): Collection
    {
    return ArticleOnMain::with('article')->active()->sort()->get();
    }

    /**
    * @return Collection|ProductCategoryOnMain[]
    */
    public function getProductCategories(): Collection
    {
    return ProductCategoryOnMain::whereHas('category', function ($q) {
    $q->active();
    })->active()->sort()->get();
    }

    /**
    * @return Collection|Slider[]
    */
    public function getSliders(): Collection
    {
    return Slider::active()->sort()->get();
    }

    /**
    * @return Page
    */
    public function getPage(): Page
    {
    return Page::query()->whereUrl('/')->firstOrFail();
    }
    }