- /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 格式
43 lines
915 B
PHP
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();
|
|
}
|
|
}
|