Color palette support in byos_laravel

This commit is contained in:
Dan van Kley 2025-11-17 20:48:06 -05:00
parent c157dcf3b6
commit 9ee7bc1aac
7 changed files with 236 additions and 4 deletions

View file

@ -6,6 +6,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
final class DeviceModel extends Model
{
@ -25,6 +26,11 @@ final class DeviceModel extends Model
'published_at' => 'datetime',
];
public function palette(): BelongsTo
{
return $this->belongsTo(Palette::class);
}
public function getColorDepthAttribute(): ?string
{
if (! $this->bit_depth) {

32
app/Models/Palette.php Normal file
View file

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Palette model representing color palettes used by device models.
*
* @property int $id
* @property string $name
* @property string $description
* @property string $palette JSON single dimension array where each entry is a 24-bit number
* representing the RGB color code.
*/
final class Palette extends Model
{
use HasFactory;
public $timestamps = false;
protected $guarded = ['id'];
public function deviceModels(): HasMany
{
return $this->hasMany(DeviceModel::class);
}
}