Add Cards

main
Alex 2 years ago
parent af874ab1e8
commit b18d98ae81

@ -0,0 +1,18 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class CardController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('cards');
}
}

@ -8,4 +8,33 @@ use Illuminate\Database\Eloquent\Model;
class Card extends Model class Card extends Model
{ {
use HasFactory; use HasFactory;
protected $fillable = [
'name',
'describtion',
'type',
'value',
'meaning',
'meaning_rev'
];
/**
* The tags that belong to the Card
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function tags(): BelongsToMany
{
return $this->belongsToMany(Tag::class, 'cards_tags', 'tags_id', 'cards_id');
}
/**
* Get the Deck associated with the Card
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function deck(): HasOne
{
return $this->hasOne(Deck::class, 'decks_id', 'card_id');
}
} }

@ -13,6 +13,16 @@ return new class extends Migration
{ {
Schema::create('cards', function (Blueprint $table) { Schema::create('cards', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('unique_id')->unique(); # Sollte eine Mix-Kennung aus Deck, Type, CardValue sein
$table->string('name');
$table->string('description');
$table->unsignedBiginteger('deck_id');
$table->foreign('deck_id')->references('id')->on('decks')->onDelete('cascade');
$table->string('type');
$table->string('value');
$table->integer('value_int');
$table->string('meaning');
$table->string('meaning_rev');
$table->timestamps(); $table->timestamps();
}); });
} }

Loading…
Cancel
Save