2013-06-19 153 views
0

我需要在實體2,實體1和類型之間創建多態關係。 事件和類型之間的關係很容易做到,但是在Entity2和Types之間的關係中存在一個問題,因爲它是一個多對多的關係。多對多多態關係

enter image description here

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'); 
     } 
    } 

回答