<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Jenssegers\Mongodb\Eloquent\Model;
class Post extends Model
{
use HasFactory;
protected $guarded = [];
protected $connection = 'mongodb';
public function tags()
{
return $this->morphToMany(Tag::class, 'taggable');
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Jenssegers\Mongodb\Eloquent\Model;
class Tag extends Model
{
use HasFactory;
protected $connection = 'mongodb';
protected $guarded = [];
public function posts()
{
return $this->morphedByMany(Post::class, 'taggable');
}
}
tags.find({"$and":[{"taggables.taggable_id":{"$in":["621b30473a86531fe1361a13"]}},{"taggables.taggable_type":"App\\Models\\Post"}]},{"projection":{"tags.*":true,"taggables.taggable_id as pivot_taggable_id":true,"taggables.tag_id as pivot_tag_id":true,"taggables.taggable_type as pivot_taggable_type":true},"typeMap":{"root":"array","document":"array"}})
@jenssegers @divine
Description:
Steps to reproduce
Post Model :
posts collection :
Tag Model :
tags collection :
taggables collection :
query :
result :
query show in laravel debugbar