✏️ 编辑:BlogPost.php
路径:
/home/boguraj1/.trash/app/Models/BlogPost.php
大小:1.07 KB · 修改:2026-07-23 16:13:46 · 权限:0644 · 可写
← 返回目录
👁 查看
⬇ 下载
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; class BlogPost extends Model { protected $fillable = ['title', 'slug', 'excerpt', 'content', 'image', 'status', 'published_at']; protected $casts = [ 'status' => 'boolean', 'published_at' => 'datetime', ]; protected static function boot() { parent::boot(); static::creating(function ($post) { if (empty($post->slug)) { $post->slug = Str::slug($post->title); } if (empty($post->excerpt) && $post->content) { $post->excerpt = Str::limit(strip_tags($post->content), 160); } }); } public function getImageUrlAttribute() { return $this->image ? asset('storage/' . $this->image) : asset('images/no-blog.png'); } public function scopePublished($query) { return $query->where('status', true) ->whereNotNull('published_at') ->where('published_at', '<=', now()); } }
💾 保存
取消
保存为 UTF-8,换行统一为 LF