57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class Card extends Model
|
|
{
|
|
use HasFactory, HasUuids;
|
|
|
|
protected $table = 'cards';
|
|
|
|
protected $fillable = [
|
|
'asset_id',
|
|
'name',
|
|
'description_upright',
|
|
'description_reversed',
|
|
'symbolism',
|
|
'image_url',
|
|
'description'
|
|
];
|
|
|
|
protected $casts = [
|
|
'symbolism' => 'array',
|
|
];
|
|
|
|
public function getIncrementing(): bool
|
|
{
|
|
return ! $this->usesUuidPrimaryKey();
|
|
}
|
|
|
|
public function getKeyType(): string
|
|
{
|
|
return $this->usesUuidPrimaryKey() ? 'string' : 'int';
|
|
}
|
|
|
|
public function uniqueIds(): array
|
|
{
|
|
return $this->usesUuidPrimaryKey() ? [$this->getKeyName()] : [];
|
|
}
|
|
|
|
protected function usesUuidPrimaryKey(): bool
|
|
{
|
|
if (! Schema::hasTable($this->getTable())) {
|
|
return false;
|
|
}
|
|
|
|
$column = collect(DB::select(sprintf('SHOW COLUMNS FROM `%s` LIKE "id"', $this->getTable())))->first();
|
|
|
|
return $column && str_starts_with(strtolower((string) $column->Type), 'char(36)');
|
|
}
|
|
}
|