<?php

namespace App\Filters;

use Essa\APIToolKit\Filters\QueryFilters;

class ItemFilters extends QueryFilters
{
    protected array $allowedFilters = [];

    protected array $columnSearch = ["name", "code", "category_id"];

    protected array $relationSearch = [
        "category" => ["name"],
    ];

    public function category_type($value)
    {
        return blank($value)
            ? $this->builder
            : $this->builder->whereHas(
                'category',
                fn($q) =>
                $q->where('name', 'like', "%{$value}%")
            );
    }
}
