diff --git a/app/Helpers/function.php b/app/Helpers/function.php index c8f8369..aa51933 100644 --- a/app/Helpers/function.php +++ b/app/Helpers/function.php @@ -1,126 +1,126 @@ -{$return}; - } - - return $category; - } - - return new Category; -} - -/** - * Notes: 获取文章分类详情 - * @Author: 玄尘 - * @Date : 2020/9/10 13:21 - * @param $categoryId - * @param string $result - * @return \App\Models\Article - */ -function getOneArticleBYCate($categoryId, $result = '') -{ - $info = Article::where('category_id', $categoryId)->latest('sort')->latest()->first(); - - if ($info) { - if ($result) { - return $info->{$result}; - } - - return $info; - } else { - return ''; - } - - return new Article; -} - -/** - * Notes: 获取分类下的文章 - * @Author: 玄尘 - * @Date : 2020/9/10 10:05 - * @param $categoryId - * @param $take - * @return \App\Models\Article - */ -function getArticlesBYCate($categoryId, $take = 8, $mark = 'one') -{ - if ($mark == 'one') { - $articles = Article::where('category_id', $categoryId) - ->where('status', 1) - ->latest('sort') - ->latest() - ->take($take) - ->get(); - } else { - $cate = Category::find($categoryId); - $ids = $cate->getAllChildrenId(); - - $articles = Article::whereIn('category_id', $ids) - ->where('status', 1) - ->latest('sort') - ->latest() - ->take($take) - ->get(); - } - - return $articles; -} - -//获取子分类 -function getCateChild($categoryId) -{ - return Category::where('status', 1) - ->where('parent_id', $categoryId) - ->orderBy('order', 'asc') - ->get(); -} - -//获取顶级分类 -function getTopCate($categoryId) -{ - $parent = Category::find($categoryId); - - while ($parent->parent_id != 0) { - $parent = $parent->parent; - } - - return $parent; -} - -//获取一个广告 -function getOneAdvertByCate($categoryId, $result = '') -{ - $info = Advert::where('category_id', $categoryId) - ->latest('sort') - ->latest() - ->first(); - if ($info) { - if ($result) { - return $info->{$result}; - } - - return $info; - } else { - return ''; - } - - return new Advert; -} - -function getAdvertsByCate($categoryId, $take = 8) -{ - return Advert::where('category_id', $categoryId) - ->latest('sort') - ->latest() - ->take($take)->get(); -} - +{$return}; + } + + return $category; + } + + return new Category; +} + +/** + * Notes: 获取文章分类详情 + * @Author: 玄尘 + * @Date : 2020/9/10 13:21 + * @param $categoryId + * @param string $result + * @return \App\Models\Article + */ +function getOneArticleBYCate($categoryId, $result = '') +{ + $info = Article::where('category_id', $categoryId)->latest('sort')->latest()->first(); + + if ($info) { + if ($result) { + return $info->{$result}; + } + + return $info; + } else { + return ''; + } + + return new Article; +} + +/** + * Notes: 获取分类下的文章 + * @Author: 玄尘 + * @Date : 2020/9/10 10:05 + * @param $categoryId + * @param $take + * @return \App\Models\Article + */ +function getArticlesBYCate($categoryId, $take = 8, $mark = 'one') +{ + if ($mark == 'one') { + $articles = Article::where('category_id', $categoryId) + ->where('status', 1) + ->latest('sort') + ->latest() + ->take($take) + ->get(); + } else { + $cate = Category::find($categoryId); + $ids = $cate->getAllChildrenId(); + + $articles = Article::whereIn('category_id', $ids) + ->where('status', 1) + ->latest('sort') + ->latest() + ->take($take) + ->get(); + } + + return $articles; +} + +//获取子分类 +function getCateChild($categoryId) +{ + return Category::where('status', 1) + ->where('parent_id', $categoryId) + ->orderBy('order', 'asc') + ->get(); +} + +//获取顶级分类 +function getTopCate($categoryId) +{ + $parent = Category::find($categoryId); + + while ($parent->parent_id != 0) { + $parent = $parent->parent; + } + + return $parent; +} + +//获取一个广告 +function getOneAdvertByCate($categoryId, $result = '') +{ + $info = Advert::where('category_id', $categoryId) + ->latest('sort') + ->latest() + ->first(); + if ($info) { + if ($result) { + return $info->{$result}; + } + + return $info; + } else { + return ''; + } + + return new Advert; +} + +function getAdvertsByCate($categoryId, $take = 8) +{ + return Advert::where('category_id', $categoryId) + ->latest('sort') + ->latest() + ->take($take)->get(); +} + diff --git a/resources/views/index/index.blade.php b/resources/views/index/index.blade.php index baac99a..8ccee90 100644 --- a/resources/views/index/index.blade.php +++ b/resources/views/index/index.blade.php @@ -83,20 +83,22 @@
{{ $article->created_at->format('Y-m') }}
- + +{{ $article->created_at->format('Y-m') }}
+{{ $article->description }}
@@ -105,15 +107,16 @@ @endif{{ $article->created_at->format('Y-m') }}
- + +{{ $article->created_at->format('Y-m') }}
+{{ $article->description }}
@@ -125,19 +128,18 @@- {{ $article->description }} -
+{{ $article->description }}
{{ $article->created_at->format('Y-m') }}
- + + + +{{ $article->description }}
@@ -183,12 +186,12 @@{{ $article->description }}
@@ -203,42 +206,8 @@ @foreach (getArticlesBYCate(14,4) as $article){{ $article->description }}
- -{{ $article->created_at->format('Y-m') }}
- -{{ $article->description }}
- -{{ $article->created_at->format('Y-m') }}
- + +{{ $article->description }}
@@ -250,23 +219,40 @@{{ $article->description }}
+ +{{ $article->description }}
+ +{{ $article->description }}
- -