Laravelのドキュメントでは、多対多の多様な関係であるmorphedByMany
リレーションを取得するための次の例があります。Laravel Eloquent内のすべてのmorphedByMany関係を取得する
Laravel Many to Many polymorphic relations documentation
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');
}
}
は、どのように私は私が後でそれもphotos
(か何か)を、追加した場合、その後posts
とvideos
、例えば、1クエリ/コレクション内のすべてのmorphed
関係のリストを取得し、でしょうか?
エヴァー解決策を見つけますか? – robjbrain
私はしましたが、私はコードを持っていませんでした。これは古い仕事でした...私がしたのは、基本的にクエリービルダーを使用して結果を取得し、カスタムコレクションクラスのデータでモデルを構築することでした。 –