调整分类
This commit is contained in:
@@ -49,7 +49,12 @@ function getOneCategory($categoryId, $return = '')
|
||||
*/
|
||||
function getOneArticleBYCate($categoryId, $result = '')
|
||||
{
|
||||
$info = Article::where('category_id', $categoryId)->latest('sort')->latest()->first();
|
||||
$info = Article::latest('sort')
|
||||
->whereHas('categories', function ($q) use ($categoryId) {
|
||||
$q->where('id', $categoryId);
|
||||
})
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if ($info) {
|
||||
if ($result) {
|
||||
@@ -78,8 +83,10 @@ function getOneArticleBYCate($categoryId, $result = '')
|
||||
function getArticlesBYCate($categoryId, $take = 8, $mark = 'one', $hasCover = false, $order = 'desc')
|
||||
{
|
||||
if ($mark == 'one') {
|
||||
$articles = Article::where('category_id', $categoryId)
|
||||
->where('status', 1)
|
||||
$articles = Article::where('status', 1)
|
||||
->whereHas('categories', function ($q) use ($categoryId) {
|
||||
$q->where('id', $categoryId);
|
||||
})
|
||||
->orderBy('sort', $order)
|
||||
->when($hasCover, function ($q) {
|
||||
$q->whereNotNull('cover');
|
||||
@@ -90,8 +97,10 @@ function getArticlesBYCate($categoryId, $take = 8, $mark = 'one', $hasCover = fa
|
||||
$cate = Category::find($categoryId);
|
||||
$ids = $cate->getAllChildrenId();
|
||||
|
||||
$articles = Article::whereIn('category_id', $ids)
|
||||
->where('status', 1)
|
||||
$articles = Article::where('status', 1)
|
||||
->whereHas('categories', function ($q) use ($ids) {
|
||||
$q->whereIN('id', $ids);
|
||||
})
|
||||
->when($hasCover, function ($q) {
|
||||
$q->whereNotNull('cover');
|
||||
})
|
||||
@@ -157,11 +166,13 @@ function getArticlesByCateIds($take = 8, $hasCover = false)
|
||||
{
|
||||
$ids = [7, 17, 8, 5, 12, 30];
|
||||
|
||||
$articles = Article::whereIn('category_id', $ids)
|
||||
->where('status', 1)
|
||||
$articles = Article::where('status', 1)
|
||||
->whereHas('categories', function ($q) use ($ids) {
|
||||
$q->whereIN('id', $ids);
|
||||
})
|
||||
->latest()
|
||||
->when($hasCover, function ($q) {
|
||||
$q->whereNotNull('cover');
|
||||
$q->whereNotNull('cover')->orWhere('cover', '<>', '');
|
||||
})
|
||||
->take($take)
|
||||
->get();
|
||||
|
||||
Reference in New Issue
Block a user