检索所有变形的ByMany关系在Laravel Eloquent
2022-08-30 17:52:46
在 Laravel 文档中,有以下用于检索关系的示例,这些关系是多对多多态关系。morphedByMany
namespace App;
use Illuminate\Database\Eloquent\Model;
class Tag extends Model
{
/**
* Get all of the posts that are assigned this tag.
*/
public function posts()
{
return $this->morphedByMany('App\Post', 'taggable');
}
/**
* Get all of the videos that are assigned this tag.
*/
public function videos()
{
return $this->morphedByMany('App\Video', 'taggable');
}
}
例如,我如何在一个查询/集合中获取所有关系的列表,然后如果我后来添加(或任何东西),那也是?morphed
posts
videos
photos