Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php namespace Api\Test;
- use Api\Entity\CategoryEntity;
- use Api\Entity\SubscriptionEntity;
- use Api\Entity\TestEntity;
- use Api\Model\Test;
- use DeSmart\DomainCore\Repository\AbstractEloquentRepository;
- use DeSmart\DomainCore\Repository\BaseEloquentRepositoryTrait;
- class TestRepository extends AbstractEloquentRepository
- {
- use BaseEloquentRepositoryTrait;
- public function __construct(Test $query)
- {
- $this->query = $query;
- }
- /**
- * Zwraca dostępne testy dla użytkownika.
- *
- * @param string $gender
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public function getAvailableTests($gender)
- {
- $query = $this->query->where('is_active', 1)
- ->whereRaw('finished_at >= NOW()')
- ->applyGender($gender)
- ->with([
- 'subscription',
- 'category'
- ]);
- $items = $this->hydrate($query->get());
- return $items->each(function (TestEntity $test) {
- $eloquent = $test->getEloquentModel();
- $test->setSubscription(new SubscriptionEntity($eloquent->subscription));
- $test->setCategory(new CategoryEntity($eloquent->category));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement