## Get the product tags
Tag relation in product model:
<?php
public function tags()
{
return $this->morphToMany(Tag::class, 'taggable', 'tag_relation', 'relationid', 'tag_id')
->withTimestamps()
->where('relation_type', 'product')
->where('gender_type', 2); // bayan
}
<?php
$product = App\Models\Product::with('tags')->find(1);
Products relation in tag model:
<?php
public function products()
{
return $this->morphedByMany(Product::class, 'taggable', 'tag_relation', 'tag_id', 'relationid')
->withTimestamps()
->where('relation_type', 'product');
}
<?php
App\Models\Tag::with('products')->where('name', 'kırmızı')->get()
<?php
$product = App\Models\Product::find(1);
$tag = new App\Models\Tag(['name' => 'Kırmızı']);
$product->tags()->save($tag, ['gender_type' => 1, 'relation_type' => 'product'])