调整导航
This commit is contained in:
@@ -1,99 +1,111 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Article;
|
||||
use App\Models\Patent;
|
||||
|
||||
function getOneCategory($categoryId, $return = '')
|
||||
{
|
||||
$category = Category::find($categoryId);
|
||||
if ($category) {
|
||||
if ($return) {
|
||||
return $category->{$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)
|
||||
{
|
||||
$articles = Article::where('category_id', $categoryId)
|
||||
->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 getPatent($take, $type = '')
|
||||
{
|
||||
return Patent::where('status', 1)
|
||||
->when($type, function ($q) use ($type) {
|
||||
$q->where('type', $type);
|
||||
})
|
||||
->get();
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Category;
|
||||
use App\Models\Article;
|
||||
use App\Models\Patent;
|
||||
|
||||
function getOneCategory($categoryId, $return = '')
|
||||
{
|
||||
$category = Category::find($categoryId);
|
||||
if ($category) {
|
||||
if ($return) {
|
||||
return $category->{$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)
|
||||
{
|
||||
$articles = Article::where('category_id', $categoryId)
|
||||
->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 getPatent($take, $type = '')
|
||||
{
|
||||
return Patent::where('status', 1)
|
||||
->when($type, function ($q) use ($type) {
|
||||
$q->where('type', $type);
|
||||
})
|
||||
->get();
|
||||
|
||||
}
|
||||
|
||||
//获取一个图片
|
||||
function getOneAdvert($category_id, $value = '')
|
||||
{
|
||||
$info = Advert::where('category_id', $category_id)->first();
|
||||
if ($value) {
|
||||
return $info->{$value};
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user