72 lines
1.4 KiB
PHP
Executable File
72 lines
1.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Galeria extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'galerias';
|
|
|
|
protected $fillable = [
|
|
'titulo',
|
|
'descripcion',
|
|
'tipo',
|
|
'archivo',
|
|
'thumbnail',
|
|
'orden',
|
|
'activo',
|
|
];
|
|
|
|
protected $casts = [
|
|
'activo' => 'boolean',
|
|
'orden' => 'integer',
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Scope para filtrar registros activos
|
|
*/
|
|
public function scopeActivo(Builder $query): Builder
|
|
{
|
|
return $query->where('activo', true);
|
|
}
|
|
|
|
/**
|
|
* Scope para ordenar por campo orden
|
|
*/
|
|
public function scopeOrdenado(Builder $query): Builder
|
|
{
|
|
return $query->orderBy('orden', 'asc')->orderBy('created_at', 'desc');
|
|
}
|
|
|
|
/**
|
|
* Obtener el tipo de archivo como clase CSS
|
|
*/
|
|
public function getTipoClaseAttribute(): string
|
|
{
|
|
return $this->tipo === 'video' ? 'video' : 'imagen';
|
|
}
|
|
|
|
/**
|
|
* Verificar si es video
|
|
*/
|
|
public function esVideo(): bool
|
|
{
|
|
return $this->tipo === 'video';
|
|
}
|
|
|
|
/**
|
|
* Verificar si es imagen
|
|
*/
|
|
public function esImagen(): bool
|
|
{
|
|
return $this->tipo === 'imagen';
|
|
}
|
|
}
|