feature test su institution
This commit is contained in:
90
backend/app/Models/Institution.php
Normal file
90
backend/app/Models/Institution.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Lists\InstitutionCategory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Str;
|
||||
use OwenIt\Auditing\Auditable as AuditableTrait;
|
||||
use OwenIt\Auditing\Contracts\Auditable;
|
||||
|
||||
class Institution extends Model implements Auditable
|
||||
{
|
||||
use AuditableTrait;
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'category_id',
|
||||
'name',
|
||||
'abbreviation',
|
||||
'address',
|
||||
'city',
|
||||
'lat',
|
||||
'lon',
|
||||
'logo',
|
||||
'color',
|
||||
'is_storage_place',
|
||||
'legacy_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* Identificatore esterno stabile, esposto nelle rotte pubbliche/LOD e usato
|
||||
* come token nei canonical URI Linked Art. NON fillable: generato qui sotto
|
||||
* (o impostato esplicitamente dall'ETL), mai via mass assignment.
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (Institution $institution): void {
|
||||
if (empty($institution->uuid)) {
|
||||
$institution->uuid = (string) Str::orderedUuid();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'category_id' => 'integer',
|
||||
'lat' => 'float',
|
||||
'lon' => 'float',
|
||||
'is_storage_place' => 'boolean',
|
||||
'legacy_id' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* La rotta pubblica risolve per uuid, non per id auto-increment.
|
||||
*/
|
||||
public function getRouteKeyName(): string
|
||||
{
|
||||
return 'uuid';
|
||||
}
|
||||
|
||||
/**
|
||||
* Categoria dell'istituzione.
|
||||
*
|
||||
* @return BelongsTo<InstitutionCategory, $this>
|
||||
*/
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(InstitutionCategory::class, 'category_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Risorse web collegate (sito ufficiale, ticketing, social, ...).
|
||||
*
|
||||
* @return HasMany<InstitutionLink, $this>
|
||||
*/
|
||||
public function links(): HasMany
|
||||
{
|
||||
return $this->hasMany(InstitutionLink::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user