finale 2.0.0.0
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
|
||||
trait HasTagsLight
|
||||
{
|
||||
public function tags(): MorphToMany
|
||||
{
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
|
||||
public function scopeWithAllTags($query, array $tags)
|
||||
{
|
||||
foreach ($tags as $tag) {
|
||||
$query->whereHas('tags', fn ($q) => $q->where('slug', $tag));
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function scopeWithAnyTags($query, array $tags)
|
||||
{
|
||||
$query->whereHas('tags', fn ($q) => $q->whereIn('slug', $tags));
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user