first push
This commit is contained in:
125
app/Admin/Controllers/Category/IndexController.php
Normal file
125
app/Admin/Controllers/Category/IndexController.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Category;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\Category;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Layout\Column;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Layout\Content;
|
||||
use Dcat\Admin\Tree;
|
||||
use Dcat\Admin\Controllers\AdminController;
|
||||
use Dcat\Admin\Widgets\Form as WidgetForm;
|
||||
use Dcat\Admin\Widgets\Box;
|
||||
|
||||
class IndexController extends AdminController
|
||||
{
|
||||
|
||||
protected $title = '分类管理';
|
||||
|
||||
public function index(Content $content)
|
||||
{
|
||||
return $content->header('树状模型')
|
||||
->body(function (Row $row) {
|
||||
$row->column(6, $this->treeView()->render());
|
||||
$row->column(6, function (Column $column) {
|
||||
$form = new WidgetForm();
|
||||
|
||||
$form->select('parent_id', '上级分类')
|
||||
->options(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1);
|
||||
}, '一级分类'))
|
||||
->required();
|
||||
$form->text('title', '分类名称')->rules('required');
|
||||
|
||||
$form->select('type', '分类类型')
|
||||
->options(Category::TYPES)
|
||||
->when('show', function (WidgetForm $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');
|
||||
|
||||
$form->text('keywords', '关键词')->rules('nullable');
|
||||
|
||||
$form->image('cover', '封面图片')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->uniqueName();
|
||||
|
||||
$form->number('order', '排序')->default(0);
|
||||
$form->switch('top_show', '顶部导航显示');
|
||||
$form->switch('status', '显示')->default(1);
|
||||
|
||||
$form->action(admin_url('categories'));
|
||||
|
||||
$column->append((new Box('新增分类', $form))->style('success'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
protected function treeView()
|
||||
{
|
||||
|
||||
return new Tree(new Category, function (Tree $tree) {
|
||||
$tree->disableCreateButton();
|
||||
$tree->disableQuickCreateButton();
|
||||
$tree->disableEditButton();
|
||||
|
||||
$tree->branch(function ($branch) {
|
||||
if ($branch['status'] == 1) {
|
||||
$payload = "<i class='fa fa-eye text-primary'></i> ";
|
||||
} else {
|
||||
$payload = "<i class='fa fa-eye text-gray'></i> ";
|
||||
}
|
||||
$payload .= " [ID:{$branch['id']}] - ";
|
||||
$payload .= " <strong>{$branch['title']}</strong> ";
|
||||
$payload .= " <small>{$branch['type']}</small> ";
|
||||
$payload .= " <small style='color:#999'>{$branch['description']}</small>";
|
||||
|
||||
return $payload;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
protected function form()
|
||||
{
|
||||
return Form::make(new Category(), function (Form $form) {
|
||||
|
||||
$form->select('parent_id', '上级分类')->options(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1);
|
||||
}, '一级分类'));
|
||||
$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();
|
||||
|
||||
$form->textarea('description', '分类简介')->rows(4)->rules('nullable');
|
||||
$form->text('keywords', '关键词')->rules('nullable');
|
||||
$form->image('cover', 'Logo')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->uniqueName();
|
||||
|
||||
$form->number('order', '排序')->default(0)->help('正序优先');
|
||||
|
||||
$form->switch('top_show', '顶部导航显示');
|
||||
$form->switch('status', '显示')->default(1);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user