Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom filter method naming convention #204

Closed
stephenr85 opened this issue Jul 26, 2023 · 2 comments
Closed

Custom filter method naming convention #204

stephenr85 opened this issue Jul 26, 2023 · 2 comments

Comments

@stephenr85
Copy link

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().

@mehdi-fathi
Copy link
Owner

@stephenr85

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

@stephenr85
Copy link
Author

stephenr85 commented Jul 27, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants