main
Alex 2 years ago
parent da45dce558
commit af874ab1e8

@ -8,4 +8,24 @@ use Illuminate\Database\Eloquent\Model;
class Tag extends Model class Tag extends Model
{ {
use HasFactory; 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');
}
} }

@ -13,6 +13,7 @@ return new class extends Migration
{ {
Schema::create('tags', function (Blueprint $table) { Schema::create('tags', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name');
$table->timestamps(); $table->timestamps();
}); });
} }

Loading…
Cancel
Save