Tucker-Eric / EloquentFilter

An Eloquent Way To Filter Laravel Models And Their Relationships
http://tucker-eric.github.io/EloquentFilter
MIT License
1.72k stars 120 forks source link

Improvement #50

Closed gihansalpo closed 6 years ago

gihansalpo commented 6 years ago

I think it will be useful if the filterInput function changed as following,

ModelFilter.php

    public function filterInput()
    {
        foreach ($this->input as $key => $val) {
            // Call all local methods on filter
            $method = $this->getFilterMethod($key);

            if (method_exists($this, $method)) {
               /* $this->{$method}($val);*/
               $this->{$method}($val ,$this->input );

            }
        }
    }

then the example filter function would like bellow. inside that function, for an example, we can write any condition that id depends on other args parameters

class UserFilter

    public function company($id,$args)
    {
       //conditoins 
        return $this->where('company_id', $id);
    }
Tucker-Eric commented 6 years ago

You can already access other input values with the input() method.

For your use case you would do:

    public function company($id)
    {
        return $this->where('foo', $this->input('bar'))->where('company_id', $id);
    }