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

Dot notation in key name #71

Closed benrolfe closed 6 years ago

benrolfe commented 6 years ago

I'm passing through the following search criteria, but it's only searching by my name "Ben", the company name is being ignored. How do I use dot notation?

[
    'Name'  => 'Ben',
    'Company.Name'  => 'Nike',
]

Here's my PHP code:

// works
public function name($value)
{
    return $this->where('Name', 'LIKE', "%$value%");
}

// ignored
public function companyName($value)
{
    return $this->related('company', 'Name', 'LIKE', "%$value%");
}
Tucker-Eric commented 6 years ago

This currently is not supported but I'd be happy to merge this feature if you submitted a pr for it.

benrolfe commented 6 years ago

@Tucker-Eric Do you know what the issue is? Is the key ignored because of the dot? Does it throw a silent error? Does it try to match against an odd/invalid method name (eg: company.Name())?

Tucker-Eric commented 6 years ago

Yup, it tries to match an invalid method name company.Name(). Looks like Laravel's camel_case helper method doesn't strip dots.

I've just updated and published fix in 1.3.1. You should be good to go with those updates.