relacje polimorficzne wielu do wielu
Muszę utworzyć polimorficzną relację między Entity2, Entity1 i Types. relacja między zdarzeniem a Typami jest łatwa do zrobienia, ale ma problem w związku między Entity2 a Typami, ponieważ jest to relacja wiele do wielu.
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();
}
}
ponieważ relacja między typami i Entitys2 jest wiele do wielu, nie wiem, jak tworzyć, ponieważ zajmuje ona tabelę przestawną.
class Entity2 extends Eloquent {
public function types()
{
// return $this->morphMany('App\Models\Type', 'typeable');
}
}