Я следую учебнику Laravel по многим и многим отношениям здесь, на Laracasts - https://laracasts.com/series/laravel-5-fundamentals/episodes/21
Моя задача состоит в том, чтобы я создал сводную таблицу article_tag) to keep track of the many to many relations. Articles can have many tags, and tags can have many articles. So I can run
sync etc to associate
tagX
tagY
Tagz to
article1`.Однако я также хочу иметь возможность установить один из связанных тегов как «isGreenTag».Могу ли я сделать это в сводной таблице, которая отслеживает отношения «многие ко многим»?Могу ли я добавить столбец "is_green_tag"?
Вот мои Article
классовые отношения:
class Article extends Model {
public function tags() {
return $this->belongsToMany('App\Tag')->withTimestamps();
}
}
Вот мои Tag
классовые отношения:
class Tag extends Model {
public function articles() {
return $this->belongsToMany('App\Articles');
}
}
Вот моя миграция для сводной таблицы:
public function up() {
Schema.create('article_tag', function(Blueprint $table) {
$table->integer('article_id')->unsigned()->index();
$table->foreign('article_id')->references('id')->on('articles')->onDelete('cascade');
$table->integer('tag_id')->unsigned()->index();
$table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
$table->timestamps();
});
}
Могу ли я добавить в сводную таблицу миграцию $table->boolean('is_green_tag')->nullable()
?