Custom filter method naming convention
stephenr85 opened this issue · 2 comments
I don't think filter naming conventions should be a 1:1 match. This has too much potential with collision/confusion with attributes or other methods.
I'd suggest they should follow the existing builder "scopeX" naming convention, or "filterX".
For example, a "keywords" filter should be one of these:
function scopeKeywords($builder, $value)
function filterKeywords($builder, $value)
For backward compatibility, the code could still look for an exact match method, but I think the package should transition away from this.
For more flexibility, a value of the "acceptRequest" array could specify which method to use. For example:
$query->acceptRequest([
'keywords' => 'whereKeywords',
'title',
'created_at',
'updated_at',
])->filter();
This would result in calling $model->whereKeywords() with the 'keywords' request input value, defined as Model::scopeWhereKeywords().
Yes, you are right. I'm striving to add a bunch of amazing features to this package. So I'll consider a meaningful naming convention for custom methods.
Thanks for this issue