✏️ 编辑:Category.php
路径:
/home/boguraj1/.trash/app/Models/Category.php
大小:718 B · 修改:2026-07-23 16:13:46 · 权限:0644 · 可写
← 返回目录
👁 查看
⬇ 下载
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; class Category extends Model { protected $fillable = ['name', 'slug', 'description', 'image', 'status', 'sort_order']; protected static function boot() { parent::boot(); static::creating(function ($category) { if (empty($category->slug)) { $category->slug = Str::slug($category->name); } }); } public function products() { return $this->hasMany(Product::class); } public function getImageUrlAttribute() { return $this->image ? asset('storage/' . $this->image) : asset('images/no-image.png'); } }
💾 保存
取消
保存为 UTF-8,换行统一为 LF