view src/Traits/Filterable.php @ 2:b44434aaa767

Moving around the components. Made a big step in the right direction with the Builder and named joins being accessible.
author luka
date Wed, 18 Jun 2025 22:28:47 -0400
parents 56d9c64d64aa
children
line wrap: on
line source

<?php

namespace Wizard\Framework\Traits;

trait Filterable
{
    protected static $filters = [];

    public function scopeFilter($query, $validated)
    {
        $filters = static::$filters;

        foreach ($filters as $key => $filter) {

            if (isset($validated[$key])) {
                if (isset($filter['callback'])) {

                } else {
                    switch ($filter['type']) {
                        case 'value':
                        default:
                            $this->valueFilter($query, $filter, $validated[$key]);
                    }
                }
            }
        }
    }

    public function valueFilter($query, $filter, $value)
    {
        $query->where($filter['table'].'.'.$filter['column_name'], '=', $value);
    }

    // filter for dates
    public function dateFilter() {}
}