静态资源
This commit is contained in:
@@ -43,6 +43,7 @@ class IndexController extends AdminController
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
|
||||
@@ -33,6 +33,11 @@ class IndexController extends AdminController
|
||||
$grid->column('category.title', '所属分类');
|
||||
$grid->column('title', '文章标题');
|
||||
$grid->column('sort', '序号');
|
||||
$states = [
|
||||
'on' => ['value' => 1, 'text' => '打开', 'color' => 'primary'],
|
||||
'off' => ['value' => 2, 'text' => '关闭', 'color' => 'default'],
|
||||
];
|
||||
$grid->column('status', '状态')->switch($states);
|
||||
$grid->column('created_at', '创建时间');
|
||||
|
||||
return $grid;
|
||||
@@ -44,20 +49,26 @@ class IndexController extends AdminController
|
||||
|
||||
$form->text('title', '文章标题')->rules('min:2');
|
||||
$form->select('category_id', '所属分类')
|
||||
->options(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1)->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
|
||||
}, '选择分类'))
|
||||
->rules('required|min:1', [
|
||||
'required' => '必须选择所属分类',
|
||||
'min' => '必须选择所属分类',
|
||||
]);
|
||||
->options(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1)->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
|
||||
}, '选择分类'))
|
||||
->rules('required|min:1', [
|
||||
'required' => '必须选择所属分类',
|
||||
'min' => '必须选择所属分类',
|
||||
]);
|
||||
$form->textarea('description', '内容简介');
|
||||
$form->image('cover', '封面')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
$form->ueditor('content', '文章内容')->rules('required', ['required' => '详情不能为空']);
|
||||
$form->number('sort', '序号')->default(0)->rules('required', ['required' => '序号必须填写'])->help('倒序优先');
|
||||
$states = [
|
||||
'on' => ['value' => 1, 'text' => '打开', 'color' => 'success'],
|
||||
'off' => ['value' => 0, 'text' => '关闭', 'color' => 'danger'],
|
||||
];
|
||||
|
||||
$form->switch('status', '状态')->states($states)->default(1);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use Encore\Admin\Layout\Row;
|
||||
use Encore\Admin\Tree;
|
||||
use Encore\Admin\Widgets\Box;
|
||||
use Encore\Admin\Widgets\Form as WidgetsForm;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
class IndexController extends AdminController
|
||||
{
|
||||
@@ -35,6 +36,14 @@ class IndexController extends AdminController
|
||||
$form->text('title', '分类名称')->rules('required');
|
||||
$form->select('type', '分类类型')
|
||||
->options(Category::TYPES)
|
||||
->when('show', function (WidgetsForm $form) {
|
||||
$form->select('article_id', '关联文章')
|
||||
->options(function ($option, $info) {
|
||||
return Article::whereHas('category', function ($q) {
|
||||
$q->where('type', 'show');
|
||||
})->pluck('title', 'id');
|
||||
})->help('当分类类型是文章详情的时候需要选择关联文章');
|
||||
})
|
||||
->required();
|
||||
$form->textarea('description', '分类简介')
|
||||
->rules('nullable');
|
||||
@@ -43,6 +52,7 @@ class IndexController extends AdminController
|
||||
->removable()
|
||||
->uniqueName();
|
||||
$form->number('order', '排序')->default(0);
|
||||
$form->switch('top_show', '顶部导航显示')->states()->default(0);
|
||||
$form->switch('status', '显示')->states()->default(1);
|
||||
$form->action(admin_url('categories'));
|
||||
|
||||
@@ -89,6 +99,14 @@ class IndexController extends AdminController
|
||||
$form->text('title', '分类名称')->rules('required');
|
||||
$form->select('type', '分类类型')
|
||||
->options(Category::TYPES)
|
||||
->when('show', function (Form $form) {
|
||||
$form->select('article_id', '关联文章')
|
||||
->options(function ($option, $info) {
|
||||
return Article::whereHas('category', function ($q) {
|
||||
$q->where('type', 'show');
|
||||
})->pluck('title', 'id');
|
||||
})->help('当分类类型是文章详情的时候需要选择关联文章');
|
||||
})
|
||||
->required()
|
||||
->rules('required');
|
||||
$form->textarea('description', '分类简介')->rows(4)->rules('nullable');
|
||||
@@ -97,27 +115,19 @@ class IndexController extends AdminController
|
||||
->removable()
|
||||
->uniqueName();
|
||||
$form->number('order', '排序')->default(0);
|
||||
$form->select('article_id', '关联文章')
|
||||
->options(function ($option, $info) {
|
||||
$category = $this;
|
||||
if ($category) {
|
||||
return Article::where('category_id', $category->id)->pluck('title', 'id');
|
||||
} else {
|
||||
return [0 => '没有数据'];
|
||||
}
|
||||
})->help('当分类类型是文章详情的时候需要选择关联文章');
|
||||
$form->switch('top_show', '顶部导航显示')->states()->default(0);
|
||||
|
||||
$form->switch('status', '显示')->states()->default(1);
|
||||
$form->saving(function (Form $form) {
|
||||
|
||||
if (request()->has('title')) {
|
||||
if (request()->type == Category::TYPE_SHOW && empty(request()->article_id)) {
|
||||
$error = new MessageBag([
|
||||
'title' => '错误',
|
||||
'message' => '文章类型是文章详情的时候需要选择关联文章',
|
||||
]);
|
||||
|
||||
return back()->withInput()->with(compact('error'));
|
||||
// $error = new MessageBag([
|
||||
// 'title' => '错误',
|
||||
// 'message' => '文章类型是文章详情的时候需要选择关联文章',
|
||||
// ]);
|
||||
//
|
||||
// return back()->withInput()->with(compact('error'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
use Encore\Admin\Show;
|
||||
|
||||
class ExampleController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Title for current resource.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title = 'Example controller';
|
||||
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
$grid = new Grid(new ExampleModel);
|
||||
|
||||
$grid->column('id', __('ID'))->sortable();
|
||||
$grid->column('created_at', __('Created at'));
|
||||
$grid->column('updated_at', __('Updated at'));
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
$show = new Show(ExampleModel::findOrFail($id));
|
||||
|
||||
$show->field('id', __('ID'));
|
||||
$show->field('created_at', __('Created at'));
|
||||
$show->field('updated_at', __('Updated at'));
|
||||
|
||||
return $show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
$form = new Form(new ExampleModel);
|
||||
|
||||
$form->display('id', __('ID'));
|
||||
$form->display('created_at', __('Created At'));
|
||||
$form->display('updated_at', __('Updated At'));
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,11 @@ use Encore\Admin\Layout\Row;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
|
||||
public function index(Content $content)
|
||||
{
|
||||
return $content
|
||||
->title('Dashboard')
|
||||
->title('看板')
|
||||
->description('Description...')
|
||||
->row(Dashboard::title())
|
||||
->row(function (Row $row) {
|
||||
@@ -22,13 +23,14 @@ class HomeController extends Controller
|
||||
$column->append(Dashboard::environment());
|
||||
});
|
||||
|
||||
$row->column(4, function (Column $column) {
|
||||
$column->append(Dashboard::extensions());
|
||||
});
|
||||
|
||||
$row->column(4, function (Column $column) {
|
||||
$column->append(Dashboard::dependencies());
|
||||
});
|
||||
// $row->column(4, function (Column $column) {
|
||||
// $column->append(Dashboard::extensions());
|
||||
// });
|
||||
//
|
||||
// $row->column(4, function (Column $column) {
|
||||
// $column->append(Dashboard::dependencies());
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
126
app/Helpers/function.php
Normal file
126
app/Helpers/function.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Category;
|
||||
use App\Models\Article;
|
||||
|
||||
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 = 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();
|
||||
}
|
||||
|
||||
@@ -10,18 +10,20 @@ class ArticleController extends Controller
|
||||
|
||||
/**
|
||||
* 显示分类
|
||||
* @param Category $category [description]
|
||||
* @param Category $category [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function show(Article $article)
|
||||
{
|
||||
$parent = $category = $article->category;
|
||||
if ($category->childrens->isEmpty()) {
|
||||
$parent = $category->parent;
|
||||
}
|
||||
$advert = Advert::where('category_id',73)->first();
|
||||
$category = $article->category;
|
||||
$parent = getTopCate($category->id);
|
||||
|
||||
return view('article.show', compact('article', 'parent', 'category','advert'));
|
||||
$next = Article::where('id', '>', $article->id)
|
||||
->where('category_id', $article->category_id)
|
||||
->where('status', 1)
|
||||
->first();
|
||||
|
||||
return view('article.show', compact('article', 'next', 'parent'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ class CategoryController extends Controller
|
||||
|
||||
/**
|
||||
* 显示分类
|
||||
* @param Category $category [description]
|
||||
* @param Category $category [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function index(Category $category)
|
||||
@@ -18,15 +18,15 @@ class CategoryController extends Controller
|
||||
if ($category->type == Category::TYPE_SHOW && $category->article_id) {
|
||||
return redirect("articles/" . $category->article_id);
|
||||
} else {
|
||||
$articles = $category->relations(Category::TYPE_ARTICLE)->paginate();
|
||||
$articles = $category->relations(Category::TYPE_ARTICLE)->paginate(8);
|
||||
$parent = $category;
|
||||
if ($category->childrens->isEmpty()) {
|
||||
$parent = $category->parent;
|
||||
}
|
||||
|
||||
$advert = Advert::where('category_id',73)->first();
|
||||
$advert = Advert::where('category_id', 73)->first();
|
||||
|
||||
return view('category.show', compact('articles', 'category', 'parent','advert'));
|
||||
return view('category.show', compact('articles', 'category', 'parent', 'advert'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Category;
|
||||
use App\Models\Link;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
@@ -19,19 +20,15 @@ class Controller extends BaseController
|
||||
{
|
||||
//顶部分类
|
||||
$categorys = Category::where('status', 1)
|
||||
->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW])
|
||||
->where('top_show', 1)
|
||||
->orderBy('order', 'desc')
|
||||
->select('id', 'title')
|
||||
->get();
|
||||
->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW])
|
||||
->where('top_show', 1)
|
||||
->orderBy('order', 'desc')
|
||||
->select('id', 'title')
|
||||
->get();
|
||||
$links = Link::get();
|
||||
|
||||
//地步友情链接
|
||||
if (url()->current() == route('index.index')) {
|
||||
$adverts = Advert::where('category_id', 26)->get();
|
||||
View::share('adverts', $adverts);
|
||||
|
||||
}
|
||||
View::share('all_categorys', $categorys);
|
||||
View::share('links', $links);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Article;
|
||||
use App\Models\Link;
|
||||
|
||||
@@ -15,26 +16,29 @@ class IndexController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$fydt = $this->getArticle([6], 9); //分院动态
|
||||
$kydt = $this->getArticle([9], 9); //科研动态
|
||||
$ldbz = $this->getArticle([3], 4); //领导班子
|
||||
$kycg = $this->getArticle([10], 8); //科研成果
|
||||
$rctd = $this->getArticle([4], 9); //人才团队介绍
|
||||
$fydt = $this->getArticle([6], 9); //分院动态
|
||||
$kydt = $this->getArticle([9], 9); //科研动态
|
||||
$ldbz = $this->getArticle([3], 4); //领导班子
|
||||
$kycg = $this->getArticle([10], 8); //科研成果
|
||||
$rctd = $this->getArticle([4], 9); //人才团队介绍
|
||||
$info = Article::where('category_id', 2)->first(); //院所介绍
|
||||
$links = Link::get();
|
||||
|
||||
return view('index.index', compact('links', 'fydt', 'kydt', 'ldbz', 'kycg', 'rctd', 'info'));
|
||||
$advert = Advert::where('category_id', 26)->latest('sort')->first();
|
||||
$center_advert = Advert::where('category_id', 28)->latest('sort')->first();
|
||||
|
||||
return view('index.index', compact('advert', 'center_advert', 'fydt', 'kydt', 'ldbz', 'kycg', 'rctd', 'info'));
|
||||
}
|
||||
|
||||
//通用获取文章
|
||||
public function getArticle($category_ids, $take = 3)
|
||||
{
|
||||
return Article::whereIn('category_id', $category_ids)
|
||||
->select('id', 'description', 'title', 'created_at', 'cover', 'content')
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->take($take)
|
||||
->get();
|
||||
->select('id', 'description', 'title', 'created_at', 'cover', 'content')
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->take($take)
|
||||
->get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\Traits\Tree;
|
||||
|
||||
class TestController extends Controller
|
||||
{
|
||||
|
||||
use Tree;
|
||||
|
||||
public function index()
|
||||
@@ -40,9 +41,12 @@ class TestController extends Controller
|
||||
dump(count($cateids));
|
||||
dump(count($oldids));
|
||||
dump($diffids);
|
||||
|
||||
dd();
|
||||
foreach ($diffids as $diffid) {
|
||||
$info = DedeArctype::where('id', $diffid)->where('ishidden', 0)->select('id', 'reid as parent_id', 'typename as title', 'content')->first();
|
||||
$info = DedeArctype::where('id', $diffid)
|
||||
->where('ishidden', 0)
|
||||
->select('id', 'reid as parent_id', 'typename as title', 'content')
|
||||
->first();
|
||||
$data = $this->getData($info);
|
||||
Category::create($data);
|
||||
}
|
||||
@@ -83,14 +87,20 @@ class TestController extends Controller
|
||||
|
||||
public function checkArticle()
|
||||
{
|
||||
// $lists = Article::where('category_id', 0)->get();
|
||||
// foreach ($lists as $list) {
|
||||
// $old = DedeArchive::find($list->oldid);
|
||||
// $cate = Category::where('oldid', $old->typeid)->first();
|
||||
// $list->category_id = $cate->id;
|
||||
// $list->save();
|
||||
// }
|
||||
// dd();
|
||||
$lists = Article::where('category_id', 0)->get();
|
||||
|
||||
foreach ($lists as $list) {
|
||||
$old = DedeArchive::find($list->oldid);
|
||||
$cate = Category::where('oldid', $old->typeid)->first();
|
||||
if (!$cate || !$old) {
|
||||
dump($old);
|
||||
dump($cate);
|
||||
dd('出问题了');
|
||||
}
|
||||
$list->category_id = $cate->id;
|
||||
$list->save();
|
||||
}
|
||||
dd();
|
||||
$articleids = Article::where('oldid', '>', 0)->pluck('oldid');
|
||||
$oldids = DedeArchive::pluck('id');
|
||||
$diffids = array_diff($oldids->toArray(), $articleids->toArray());
|
||||
@@ -98,7 +108,7 @@ class TestController extends Controller
|
||||
dump(count($oldids));
|
||||
dump($diffids);
|
||||
die();
|
||||
$map = [
|
||||
$map = [
|
||||
'id' => ['in', $diffids],
|
||||
];
|
||||
$list = DedeArchive::whereIn('id', $diffids)->get();
|
||||
@@ -128,7 +138,7 @@ class TestController extends Controller
|
||||
dd('已经导入过数据');
|
||||
}
|
||||
$categorys = Category::get();
|
||||
$error = $success = [];
|
||||
$error = $success = [];
|
||||
DedeArchive::whereNotNull('litpic')->chunk(200, function ($articles) use ($categorys) {
|
||||
|
||||
foreach ($articles as $article) {
|
||||
@@ -168,7 +178,9 @@ class TestController extends Controller
|
||||
if ($categorys->count() > 1) {
|
||||
dd('已经导入过数据');
|
||||
}
|
||||
$lists = DedeArctype::where('ishidden', 0)->select('id', 'reid as parent_id', 'typename as title', 'content')->get();
|
||||
$lists = DedeArctype::where('ishidden', 0)
|
||||
->select('id', 'reid as parent_id', 'typename as title', 'content')
|
||||
->get();
|
||||
$list = Tree::list2tree($lists->toArray(), 'id', 'parent_id', 'children', 0);
|
||||
|
||||
foreach ($list as $key => $value) {
|
||||
@@ -191,6 +203,7 @@ class TestController extends Controller
|
||||
'content' => $category['content'],
|
||||
'status' => 1,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,14 @@ use App\Models\Traits\HasOneCover;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
|
||||
use HasOneCover, BelongsToCategory;
|
||||
|
||||
public function getLinkAttribute()
|
||||
{
|
||||
return route('article.show', $this);
|
||||
}
|
||||
|
||||
public function get_content_cover()
|
||||
{
|
||||
preg_match("/<img.*?src=\"([^\"]+)\"[^>].*?>/isU", str_ireplace("\\", "", $this->content), $matches);
|
||||
@@ -39,6 +45,7 @@ class Article extends Model
|
||||
$path = config('app.url') . $path;
|
||||
|
||||
}
|
||||
|
||||
return $path;
|
||||
|
||||
}
|
||||
|
||||
@@ -7,17 +7,22 @@ use Encore\Admin\Traits\ModelTree;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
|
||||
use AdminBuilder, ModelTree;
|
||||
|
||||
public const TYPES = [
|
||||
'article' => '文章列表',
|
||||
'show' => '文章详情',
|
||||
'advert' => '广告',
|
||||
];
|
||||
|
||||
public const TYPE_SHOW = 'show';
|
||||
public const TYPE_SHOW = 'show';
|
||||
public const TYPE_ARTICLE = 'article';
|
||||
public const TYPE_ADVERT = 'advert';
|
||||
public const TYPES = [
|
||||
self::TYPE_ARTICLE => '文章列表',
|
||||
self::TYPE_SHOW => '文章详情',
|
||||
self::TYPE_ADVERT => '图片',
|
||||
];
|
||||
|
||||
public function getLinkAttribute()
|
||||
{
|
||||
return route('category.show', $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联的数据
|
||||
@@ -42,12 +47,12 @@ class Category extends Model
|
||||
|
||||
public function childrens()
|
||||
{
|
||||
return $this->hasMany(self::class,'parent_id');
|
||||
return $this->hasMany(self::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->hasOne(self::class,'id','parent_id');
|
||||
return $this->hasOne(self::class, 'id', 'parent_id');
|
||||
}
|
||||
|
||||
public function article()
|
||||
|
||||
Reference in New Issue
Block a user