Initial commit: Lash Vanshy - Complete project with admin panel, gallery, products, and contact
This commit is contained in:
76
app/Models/Producto.php
Executable file
76
app/Models/Producto.php
Executable file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Producto extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'productos';
|
||||
|
||||
protected $fillable = [
|
||||
'nombre',
|
||||
'descripcion',
|
||||
'precio',
|
||||
'imagen',
|
||||
'categoria',
|
||||
'destacado',
|
||||
'activo',
|
||||
'orden',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'precio' => 'decimal:2',
|
||||
'destacado' => 'boolean',
|
||||
'activo' => 'boolean',
|
||||
'orden' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Scope para filtrar productos activos
|
||||
*/
|
||||
public function scopeActivo(Builder $query): Builder
|
||||
{
|
||||
return $query->where('activo', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope para filtrar productos destacados
|
||||
*/
|
||||
public function scopeDestacado(Builder $query): Builder
|
||||
{
|
||||
return $query->where('destacado', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope para filtrar por categoría
|
||||
*/
|
||||
public function scopePorCategoria(Builder $query, string $categoria): Builder
|
||||
{
|
||||
return $query->where('categoria', $categoria);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtener precio formateado
|
||||
*/
|
||||
public function getPrecioFormateadoAttribute(): string
|
||||
{
|
||||
$currency = config('currency');
|
||||
|
||||
return $currency['symbol'].number_format($this->precio, $currency['decimal_places'], $currency['decimal_separator'], $currency['thousands_separator']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verificar si tiene imagen
|
||||
*/
|
||||
public function tieneImagen(): bool
|
||||
{
|
||||
return ! empty($this->imagen);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user