33 lines
781 B
PHP
33 lines
781 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||
|
|
|
||
|
|
class TipologiaDocumento extends Model
|
||
|
|
{
|
||
|
|
protected $table = 'tipologie_documenti';
|
||
|
|
|
||
|
|
protected $fillable = ['nome', 'descrizione', 'ordine', 'attiva'];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'attiva' => 'boolean',
|
||
|
|
'ordine' => 'integer',
|
||
|
|
];
|
||
|
|
|
||
|
|
public function documenti(): HasMany
|
||
|
|
{
|
||
|
|
return $this->hasMany(Documento::class, 'tipologia', 'nome');
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function attive(): \Illuminate\Database\Eloquent\Collection
|
||
|
|
{
|
||
|
|
return static::where('attiva', true)->orderBy('ordine')->get();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function opzioni(): array
|
||
|
|
{
|
||
|
|
return static::attive()->pluck('nome')->toArray();
|
||
|
|
}
|
||
|
|
}
|