Files
laralog/app/Models/Category.php
T
gouki f5987e7cc2
Build and Deploy / verify (push) Successful in 1m6s
Build and Deploy / deploy (push) Successful in 41s
refactor(routes): canonical URLs now match sablog format exactly
- /show-{id}.shtml (comments page: /show-{id}-{page}.shtml)
- /category-{cid}.shtml / /category-{cid}-{page}.shtml
- /archives-{YYYYMM}.shtml / /archives-{YYYYMM}-{page}.shtml
- /tag/{name}, /tagslist.shtml, /index-{page}.shtml
- slug 时代的 /posts/{slug} 等旧格式全部 301 到 sablog 格式
2026-09-09 21:21:07 +00:00

43 lines
915 B
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
class Category extends Model implements HasMedia
{
use HasFactory;
use InteractsWithMedia;
protected $fillable = [
'name',
'slug',
'display_order',
'post_count',
'description',
];
public function posts(): HasMany
{
return $this->hasMany(Post::class);
}
public function getUrlAttribute(): string
{
return route('category.show', $this->id);
}
public function registerMediaCollections(): void
{
$this->addMediaCollection('cover')
->useDisk(\App\Support\MediaDisk::name())
->singleFile();
}
}