diff --git a/app/Http/Controllers/Api/ComponentController.php b/app/Http/Controllers/Api/ComponentController.php index 4b9d2964..93da74dd 100644 --- a/app/Http/Controllers/Api/ComponentController.php +++ b/app/Http/Controllers/Api/ComponentController.php @@ -37,6 +37,10 @@ class ComponentController extends AbstractApiController $components = Component::enabled(); } + if ($tags = Binput::get('tags')) { + $components->withAnyTags($tags); + } + $components->search(Binput::except(['sort', 'order', 'per_page'])); if ($sortBy = Binput::get('sort')) { diff --git a/app/Models/Component.php b/app/Models/Component.php index 49bfa875..2504e99c 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -14,7 +14,7 @@ namespace CachetHQ\Cachet\Models; use AltThree\Validator\ValidatingTrait; use CachetHQ\Cachet\Models\Traits\SearchableTrait; use CachetHQ\Cachet\Models\Traits\SortableTrait; -use CachetHQ\Cachet\Models\Traits\Taggable; +use CachetHQ\Cachet\Models\Traits\HasTags; use CachetHQ\Cachet\Presenters\ComponentPresenter; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; @@ -23,7 +23,7 @@ use McCool\LaravelAutoPresenter\HasPresenter; class Component extends Model implements HasPresenter { - use SearchableTrait, SoftDeletes, SortableTrait, Taggable, ValidatingTrait; + use HasTags, SearchableTrait, SoftDeletes, SortableTrait, ValidatingTrait; /** * List of attributes that have default values. diff --git a/app/Models/Incident.php b/app/Models/Incident.php index 8e41e95b..37401ded 100644 --- a/app/Models/Incident.php +++ b/app/Models/Incident.php @@ -14,7 +14,7 @@ namespace CachetHQ\Cachet\Models; use AltThree\Validator\ValidatingTrait; use CachetHQ\Cachet\Models\Traits\SearchableTrait; use CachetHQ\Cachet\Models\Traits\SortableTrait; -use CachetHQ\Cachet\Models\Traits\Taggable; +use CachetHQ\Cachet\Models\Traits\HasTags; use CachetHQ\Cachet\Presenters\IncidentPresenter; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; @@ -30,7 +30,7 @@ use McCool\LaravelAutoPresenter\HasPresenter; */ class Incident extends Model implements HasPresenter { - use SearchableTrait, SoftDeletes, SortableTrait, Taggable, ValidatingTrait; + use HasTags, SearchableTrait, SoftDeletes, SortableTrait, ValidatingTrait; /** * Status for incident being investigated. diff --git a/app/Models/Traits/Taggable.php b/app/Models/Traits/HasTags.php similarity index 89% rename from app/Models/Traits/Taggable.php rename to app/Models/Traits/HasTags.php index 7a3e0024..a2fae75f 100644 --- a/app/Models/Traits/Taggable.php +++ b/app/Models/Traits/HasTags.php @@ -12,16 +12,15 @@ namespace CachetHQ\Cachet\Models\Traits; use CachetHQ\Cachet\Models\Tag; -use CachetHQ\Cachet\Models\Taggable as TaggableModel; use Illuminate\Database\Eloquent\Builder; use InvalidArgumentException; /** - * This is the taggable trait. + * This is the has tags trait. * * @author James Brooks */ -trait Taggable +trait HasTags { /** * Get the tags relation. @@ -43,7 +42,7 @@ trait Taggable { $tags = static::convertToTags($tags); - return $tags->each(function ($tag) use ($query) { + $tags->each(function ($tag) use ($query) { $query->whereHas('tags', function (Builder $query) use ($tag) { return $query->where('id', $tag ? $tag->id : 0); }); @@ -65,9 +64,7 @@ trait Taggable return $query->whereHas('tags', function (Builder $query) use ($tags) { $tagIds = $tags->pluck('id')->toArray(); - // dd($tagIds); - - $query->where('taggables.tag_id', '=', 1); + $query->whereIn('taggables.tag_id', $tagIds); }); }