cviebrock / eloquent-taggable

Easily add the ability to tag your Eloquent models in Laravel.
MIT License
537 stars 72 forks source link

Create a new alias to use on scopes to be able to combine many scopes #97

Closed devguar closed 5 years ago

devguar commented 5 years ago

Create a new alias to use on scopes to be able to combine many scopes. This way we can use the same scope more than once.

Like this:

// Find models with any one of the given tags
// i.e. everything tagged "Apple OR Banana".
// AND tagged "Cherry OR Durian".
// (returns Ids: 4, 6, 7, 8)

Model::withAnyTags('Apple,Banana')::withAnyTags('Cherry,Durian')->get();

//4 - Apple, Banana, Cherry
//6 - Apple, Durian
//7 - Banana, Durian
//8 - Apple, Banana, Durian

This is different than:

Model::withAnyTags('Apple,Banana,Cherry,Durian')->get();

//That returns this models:
//2 - Apple
//3 - Apple,Banana
//4 - Apple, Banana, Cherry
//5 - Cherry
//6 - Apple, Durian
//7 - Banana, Durian
//8 - Apple, Banana, Durian

Please make sure you've read CONTRIBUTING.md before submitting your pull request, and that you have:

Thank you!

cviebrock commented 5 years ago

Cool ... thanks!

cviebrock commented 5 years ago

Available in 3.5.3.