diff --git a/src/app/Models/Tag.php b/src/app/Models/Tag.php index 6b7af87..1177352 100644 --- a/src/app/Models/Tag.php +++ b/src/app/Models/Tag.php @@ -8,4 +8,24 @@ use Illuminate\Database\Eloquent\Model; class Tag extends Model { use HasFactory; + + /** + * The decks that belong to the Tag + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function decks(): BelongsToMany + { + return $this->belongsToMany(Deck::class, 'decks_tags', 'decks_id', 'tags_id'); + } + + /** + * The Cards that belong to the Tag + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function cards(): BelongsToMany + { + return $this->belongsToMany(Card::class, 'cards_tags', 'cards_id', 'tags_id'); + } } diff --git a/src/database/migrations/2023_07_08_152018_create_tags_table.php b/src/database/migrations/2023_07_08_152018_create_tags_table.php index 85f6a52..38167d8 100644 --- a/src/database/migrations/2023_07_08_152018_create_tags_table.php +++ b/src/database/migrations/2023_07_08_152018_create_tags_table.php @@ -13,6 +13,7 @@ return new class extends Migration { Schema::create('tags', function (Blueprint $table) { $table->id(); + $table->string('name'); $table->timestamps(); }); }