调整页面
This commit is contained in:
@@ -20,19 +20,20 @@ function getOneCategory($categoryId, $return = '')
|
||||
|
||||
/**
|
||||
* Notes: 获取文章分类详情
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/9/10 13:21
|
||||
* @param $categoryId
|
||||
* @param string $result
|
||||
* @param string $result
|
||||
* @return \App\Models\Article
|
||||
*/
|
||||
function getOneArticleBYCate($categoryId, $result = '')
|
||||
{
|
||||
$info = Article::where('status', 1)
|
||||
->ByCategory($categoryId)
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->first();
|
||||
->ByCategory($categoryId)
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if ($info) {
|
||||
if ($result) {
|
||||
@@ -49,6 +50,7 @@ function getOneArticleBYCate($categoryId, $result = '')
|
||||
|
||||
/**
|
||||
* Notes: 获取分类下的文章
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/9/10 10:05
|
||||
* @param $categoryId
|
||||
@@ -59,33 +61,58 @@ function getArticlesBYCate($categoryId, $take = 8, $mark = 'one')
|
||||
{
|
||||
if ($mark == 'one') {
|
||||
$articles = Article::where('status', 1)
|
||||
->ByCategory($categoryId)
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->take($take)
|
||||
->get();
|
||||
->ByCategory($categoryId)
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->take($take)
|
||||
->get();
|
||||
} else {
|
||||
$cate = Category::find($categoryId);
|
||||
$ids = $cate->getAllChildrenId();
|
||||
|
||||
$articles = Article::where('status', 1)
|
||||
->ByCategory($ids)
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->take($take)
|
||||
->get();
|
||||
->ByCategory($ids)
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->take($take)
|
||||
->get();
|
||||
}
|
||||
|
||||
return $articles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 获取带图片的文章
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2022/3/4 16:52
|
||||
* @param $categoryId
|
||||
* @param $take
|
||||
* @return mixed
|
||||
*/
|
||||
function getArticlesAndCoverBYCate($categoryId, $take = 8)
|
||||
{
|
||||
$cate = Category::find($categoryId);
|
||||
$ids = $cate->getAllChildrenId();
|
||||
|
||||
return Article::where('status', 1)
|
||||
->ByCategory($ids)
|
||||
->where(function ($query) {
|
||||
$query->whereNotNull('cover')->orWhere('cover', '<>', '');
|
||||
})
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->take($take)
|
||||
->get();
|
||||
}
|
||||
|
||||
//获取子分类
|
||||
function getCateChild($categoryId)
|
||||
{
|
||||
return Category::where('status', 1)
|
||||
->where('parent_id', $categoryId)
|
||||
->orderBy('order', 'asc')
|
||||
->get();
|
||||
->where('parent_id', $categoryId)
|
||||
->orderBy('order', 'asc')
|
||||
->get();
|
||||
}
|
||||
|
||||
//获取顶级分类
|
||||
@@ -104,9 +131,9 @@ function getTopCate($categoryId)
|
||||
function getOneAdvertByCate($categoryId, $result = '')
|
||||
{
|
||||
$info = Advert::where('category_id', $categoryId)
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->first();
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->first();
|
||||
if ($info) {
|
||||
if ($result) {
|
||||
return $info->{$result};
|
||||
@@ -123,8 +150,8 @@ function getOneAdvertByCate($categoryId, $result = '')
|
||||
function getAdvertsByCate($categoryId, $take = 8)
|
||||
{
|
||||
return Advert::where('category_id', $categoryId)
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->take($take)->get();
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->take($take)->get();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Article;
|
||||
use App\Models\Category;
|
||||
|
||||
class CategoryController extends Controller
|
||||
@@ -10,20 +11,28 @@ class CategoryController extends Controller
|
||||
|
||||
/**
|
||||
* 显示分类
|
||||
*
|
||||
* @param Category $category [description]
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View [type] [description]
|
||||
*/
|
||||
public function index(Category $category)
|
||||
{
|
||||
if ($category->type == Category::TYPE_SHOW && $category->article_id) {
|
||||
return redirect("articles/" . $category->article_id);
|
||||
return redirect("articles/".$category->article_id);
|
||||
} else {
|
||||
$articles = $category->relations(Category::TYPE_ARTICLE)
|
||||
->where('status', 1)
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->paginate();
|
||||
$parent = $category;
|
||||
// $articles = $category->relations(Category::TYPE_ARTICLE)
|
||||
// ->where('status', 1)
|
||||
// ->latest('sort')
|
||||
// ->latest()
|
||||
// ->paginate();
|
||||
|
||||
$articles = Article::ByCategory($category->getAllChildrenId())
|
||||
->where('status', 1)
|
||||
->latest()
|
||||
->latest('created_at')
|
||||
->paginate();
|
||||
|
||||
$parent = $category;
|
||||
|
||||
if ($category->childrens->isEmpty() && $category->parent) {
|
||||
$parent = $category->parent;
|
||||
|
||||
Reference in New Issue
Block a user