36 lines
973 B
PHP
36 lines
973 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\GpuFactory;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Gpu extends Model
|
|
{
|
|
/** @use HasFactory<GpuFactory> */
|
|
use HasFactory;
|
|
|
|
protected $fillable = ['name', 'vendor', 'active'];
|
|
|
|
/**
|
|
* Case-insensitive lookup by canonical name — the single matching rule
|
|
* used by imports and future submissions to link gpu_id.
|
|
*/
|
|
public static function match(?string $name): ?self
|
|
{
|
|
if ($name === null || trim($name) === '' || in_array(strtolower(trim($name)), ['unknown', 'hosted', 'cloud'], true)) {
|
|
return null;
|
|
}
|
|
|
|
return static::query()
|
|
->whereRaw('lower(name) = ?', [strtolower(trim($name))])
|
|
->first();
|
|
}
|
|
|
|
public function scopeActive(Builder $query): Builder
|
|
{
|
|
return $query->where('active', true);
|
|
}
|
|
}
|