文章分类由1变多

This commit is contained in:
2021-04-02 09:30:56 +08:00
parent e2699b7e04
commit 977dd11c7d
19 changed files with 177 additions and 287 deletions

View File

@@ -12,7 +12,7 @@ class ArticleController extends Controller
//文章列表
public function index(Category $category)
{
$articles = Article::where('category_id', $category->id)
$articles = Article::ByCategory($category->id)
->orderBy('created_at', 'desc')
->paginate(5);
@@ -26,15 +26,12 @@ class ArticleController extends Controller
return redirect($article->url);
}
$category = $article->category;
$next = Article::where('id', '>', $article->id)
->ByCategory($article->categories()->pluck('id'))
->where('status', 1)
->first();
$next = Article::where('id', '>', $article->id)
->where('category_id', $category->id)
->where('status', 1)
->first();
$parent = getTopCate($category->id);
return view('articles.show', compact('article', 'category', 'next', 'parent'));
return view('articles.show', compact('article', 'next'));
}
//搜索