EscolaLMS/Consultations

View on GitHub
src/Repositories/Criteria/CategoriesCriterion.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

namespace EscolaLms\Consultations\Repositories\Criteria;

use EscolaLms\Core\Repositories\Criteria\Criterion;
use Illuminate\Database\Eloquent\Builder;

class CategoriesCriterion extends Criterion
{
    public function __construct(array $value = null)
    {
        parent::__construct(null, $value);
    }

    public function apply(Builder $query): Builder
    {
        return $query->whereHas(
            'categories',
            fn (Builder $query) => $query->whereIn('categories.id', $this->value)
        );
    }
}