Skip to content

Commit f828bf6

Browse files
committed
修改文章对应目录章节下无文章的章节名称显示问题
1 parent e8d19fa commit f828bf6

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,17 @@ php artisan export:documents-seed
104104
## 待解决已知问题
105105
1.BUG问题
106106
- Dcatadmin内置的Markdown编辑器会因为文档过长造成保存后无法再次编辑文章的问题
107+
107108
2.体验优化问题
108109
-
110+
109111
3.逻辑问题
110-
- 后台有空目录(目录下没有文章)前台不展示
112+
-
113+
111114
4.Dcatadmin文档问题
112115
- 版本日志更新图片没有本地化
113116
- 文章具体内容内部链接跳转仍是learnku站点
114117

115118
## 待实现功能问题
119+
116120
1.版本管理开放开关按钮问题

app/Http/Controllers/ArticleController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ public function show(Request $request, $document_slug, $version_number, $article
3333
->where('version_id', $version->id)
3434
->where('id', $article_id)
3535
->firstOrFail();
36+
$chapters = $document->has_chapters
37+
? Chapter::with(['articles' => function($query) use ($version) {
38+
$query->where('version_id', $version->id)->orderBy('order');
39+
}])->where('version_id', $version->id)->orderBy('order')->get()
40+
: [];
3641

3742
$articles = $document->has_chapters
3843
? $version->articles()->with('chapter')->orderBy('chapter_id')->orderBy('order')->get()->groupBy('chapter_id')
3944
: $version->articles()->orderBy('order')->get();
4045

41-
return view('documents.articles.show', compact('document', 'version', 'article', 'articles'));
46+
return view('documents.articles.show', compact('document', 'version', 'article', 'chapters', 'articles'));
4247
}
4348

4449
public function findArticleIdBySlug($document_slug, $version_number, $chapter_id, $article_slug)

resources/views/documents/articles/show.blade.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,17 @@
321321
<div class="sidebar">
322322
<h5>目录</h5>
323323
@if($document->has_chapters)
324-
@foreach($articles as $chapterId => $chapterArticles)
324+
@foreach($chapters as $chapter)
325325
<div class="chapter">
326-
<div class="chapter-title" data-toggle="collapse" data-target="#chapter-{{ $chapterId }}">
326+
<div class="chapter-title" data-toggle="collapse" data-target="#chapter-{{ $chapter->id }}">
327327
<span class="toggle-icon">&#9656;</span>
328-
{{ $chapterArticles->first()->chapter->title ?? '未命名章节' }}
328+
{{ $chapter->title ?? '未命名章节' }}
329329
</div>
330-
<div class="collapse" id="chapter-{{ $chapterId }}">
331-
@if ($chapterArticles->isEmpty())
330+
<div class="collapse" id="chapter-{{ $chapter->id }}">
331+
@if ($chapter->articles->isEmpty())
332332
<div class="article-title">暂无文章</div>
333333
@else
334-
@foreach($chapterArticles as $articleItem)
334+
@foreach($chapter->articles as $articleItem)
335335
<div class="article-title">
336336
<a href="{{ route('articles.show', ['document_slug' => $document->slug, 'version' => $version->version_number, 'article_slug' => $articleItem->slug, 'article_id' => $articleItem->id]) }}">{{ $articleItem->title }}</a>
337337
</div>

0 commit comments

Comments
 (0)