Laravel 多对多多态关系

Laravel 多对多多态关系,laravel,laravel-4,polymorphic-associations,eloquent,Laravel,Laravel 4,Polymorphic Associations,Eloquent,我需要在Entity2、Entity1和类型之间创建多态关系。 事件和类型之间的关系很容易实现,但Entity2和类型之间的关系存在问题,因为这是一种多对多关系 class CreateTypesTable extends Migration { public function up() { Schema::create('types', function(Blueprint $table) { $table->increments('

我需要在Entity2、Entity1和类型之间创建多态关系。 事件和类型之间的关系很容易实现,但Entity2和类型之间的关系存在问题,因为这是一种多对多关系

class CreateTypesTable extends Migration {
   public function up()
    {
        Schema::create('types', function(Blueprint $table) {
            $table->increments('id');
            $table->integer('typeable_id');
            $table->string('typeable_type', 20);
            $table->string('name', 20);
            $table->text('description')->nullable();
        });
    }
}

class Entity1 extends Eloquent {
    public function type()
    {
        return $this->morphMany('App\Models\Type', 'typeable');
    }
}

class Type extends Eloquent {

    public function typeable()
    {
        return $this->morphTo();
    }
}

由于类型和Entitys2之间的关系是多对多的,所以不知道如何创建,因为它需要一个透视表

    class Entity2 extends Eloquent {
        public function types()
        {
//          return $this->morphMany('App\Models\Type', 'typeable');
        }
    }

对于多对多关系,您需要使用另一种多态方法:morhpToMany和belongtomany,其中您将相关模型作为参数传递