You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.2 KiB
PHP
56 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Noticia extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'noticias';
|
|
|
|
protected $fillable = [
|
|
'titulo',
|
|
'slug',
|
|
'descripcion_corta',
|
|
'contenido',
|
|
'categoria',
|
|
'tag_color',
|
|
'imagen_path',
|
|
'link_url',
|
|
'link_texto',
|
|
'fecha_publicacion',
|
|
'publicado',
|
|
'destacado',
|
|
'orden',
|
|
];
|
|
|
|
protected $casts = [
|
|
'fecha_publicacion' => 'datetime',
|
|
'publicado' => 'boolean',
|
|
'destacado' => 'boolean',
|
|
'orden' => 'integer',
|
|
];
|
|
|
|
protected $appends = ['imagen_url'];
|
|
|
|
public function getImagenUrlAttribute(): ?string
|
|
{
|
|
if (!$this->imagen_path) return null;
|
|
return asset('storage/' . ltrim($this->imagen_path, '/'));
|
|
}
|
|
|
|
// Auto-generar slug si no viene
|
|
protected static function booted(): void
|
|
{
|
|
static::saving(function (Noticia $noticia) {
|
|
if (!$noticia->slug) {
|
|
$noticia->slug = Str::slug($noticia->titulo);
|
|
}
|
|
});
|
|
}
|
|
}
|