EscolaLMS/Auth

View on GitHub
src/Repositories/Criteria/AdditionalField/AdditionalFieldLikeCriterion.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace EscolaLms\Auth\Repositories\Criteria\AdditionalField;

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

class AdditionalFieldLikeCriterion extends Criterion
{
    public function apply(Builder $query): Builder
    {
        return $query->whereHas('fields', function ($query) {
            return $query->where([
                ['name', '=', $this->key],
                ['value', 'LIKE', "%$this->value%"],
            ]);
        });
    }
}