fix(seo): read id/cid route params after sablog URL refactor
This commit is contained in:
@@ -65,9 +65,9 @@ class SeoMiddleware
|
||||
$route = $request->route();
|
||||
|
||||
if ($route && $route->getName() === 'posts.show') {
|
||||
$slug = $route->parameter('slug');
|
||||
$post = Cache::remember('seo.post.'.$slug, now()->addHour(), function () use ($slug) {
|
||||
return Post::query()->where('slug', $slug)->first();
|
||||
$id = $route->parameter('id') ?? $route->parameter('slug');
|
||||
$post = Cache::remember('seo.post.'.$id, now()->addHour(), function () use ($id) {
|
||||
return Post::query()->where('id', (int) $id)->orWhere('slug', (string) $id)->first();
|
||||
});
|
||||
|
||||
if ($post && $post->status === 'published') {
|
||||
@@ -94,9 +94,9 @@ class SeoMiddleware
|
||||
|
||||
// 分类页:面包屑结构化数据(GEO 友好)
|
||||
if ($route && $route->getName() === 'category.show') {
|
||||
$slug = $route->parameter('slug');
|
||||
$category = Cache::remember('seo.category.'.$slug, now()->addHour(), function () use ($slug) {
|
||||
return \App\Models\Category::query()->where('slug', $slug)->orWhere('id', (int) $slug)->first();
|
||||
$cid = $route->parameter('cid') ?? $route->parameter('slug');
|
||||
$category = Cache::remember('seo.category.'.$cid, now()->addHour(), function () use ($cid) {
|
||||
return \App\Models\Category::query()->where('id', (int) $cid)->orWhere('slug', (string) $cid)->first();
|
||||
});
|
||||
|
||||
if ($category) {
|
||||
|
||||
Reference in New Issue
Block a user