Initial commit: Lash Vanshy - Complete project with admin panel, gallery, products, and contact
This commit is contained in:
71
app/Models/Galeria.php
Executable file
71
app/Models/Galeria.php
Executable file
@@ -0,0 +1,71 @@
|
||||
<?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';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user