Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Sistema extends Model
|
||||
{
|
||||
protected $table = 'sistemi';
|
||||
|
||||
protected $fillable = [
|
||||
'codice', 'nome', 'ordine', 'attivo',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'ordine' => 'integer',
|
||||
'attivo' => 'boolean',
|
||||
];
|
||||
|
||||
public function modelli(): HasMany
|
||||
{
|
||||
return $this->hasMany(Modello::class);
|
||||
}
|
||||
|
||||
public function scopeAttivi(Builder $query): Builder
|
||||
{
|
||||
return $query->where('attivo', true)->orderBy('ordine')->orderBy('id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user