二次改版
This commit is contained in:
@@ -19,6 +19,7 @@ class IndexController extends AdminController
|
||||
|
||||
/**
|
||||
* Index interface.
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
public function grid()
|
||||
@@ -34,23 +35,23 @@ 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('categories', function ($q) {
|
||||
$q->where('type', 'show');
|
||||
})->pluck('title', 'id');
|
||||
})->help('当分类类型是文章详情的时候需要选择关联文章');
|
||||
})
|
||||
->required();
|
||||
->options(Category::TYPES)
|
||||
->when(Category::TYPE_LINK, function (WidgetsForm $form) {
|
||||
$form->text('uri', '跳转地址');
|
||||
})
|
||||
->required();
|
||||
$form->textarea('description', '分类简介')
|
||||
->rules('nullable');
|
||||
->rules('nullable');
|
||||
$form->image('cover', '封面')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
->move('images/'.date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
$form->image('label', '标签')
|
||||
->move('images/'.date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
$form->number('order', '排序')->default(0);
|
||||
$form->select('template', '模板')->options(config('settings.templates'));
|
||||
$form->switch('top_show', '顶部导航显示')->states()->default(0);
|
||||
$form->switch('status', '显示')->states()->default(1);
|
||||
$form->action(admin_url('categories'));
|
||||
@@ -74,9 +75,13 @@ class IndexController extends AdminController
|
||||
} else {
|
||||
$payload = "<i class='fa fa-eye text-gray'></i> ";
|
||||
}
|
||||
|
||||
$template = $branch['template'] ?? 'list';
|
||||
|
||||
$payload .= " [ID:{$branch['id']}] - ";
|
||||
$payload .= " <strong>{$branch['title']}</strong> ";
|
||||
$payload .= " <small>{$branch['type']}</small> ";
|
||||
$payload .= "【 {$template} 】";
|
||||
$payload .= " <small style='color:#999'>{$branch['description']}</small>";
|
||||
|
||||
return $payload;
|
||||
@@ -86,9 +91,10 @@ class IndexController extends AdminController
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
protected function form(): Form
|
||||
{
|
||||
$form = new Form(new Category);
|
||||
|
||||
@@ -97,23 +103,20 @@ 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('categories', function ($q) {
|
||||
$q->where('type', 'show');
|
||||
})->pluck('title', 'id');
|
||||
})->help('当分类类型是文章详情的时候需要选择关联文章');
|
||||
})
|
||||
->required()
|
||||
->rules('required');
|
||||
->options(Category::TYPES)
|
||||
->when(Category::TYPE_LINK, function (Form $form) {
|
||||
$form->text('uri', '跳转地址');
|
||||
})
|
||||
->required()
|
||||
->rules('required');
|
||||
$form->textarea('description', '分类简介')->rows(4)->rules('nullable');
|
||||
$form->image('cover', '封面')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
->move('images/'.date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
|
||||
$form->number('order', '排序')->default(0)->help('正序优先');
|
||||
$form->select('template', '模板')->options(config('settings.templates'));
|
||||
|
||||
$form->switch('status', '显示')->states()->default(1);
|
||||
$form->switch('top_show', '顶部导航显示')->states()->default(0);
|
||||
@@ -121,13 +124,13 @@ class IndexController extends AdminController
|
||||
$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'));
|
||||
if (request()->type == Category::TYPE_LINK && empty(request()->uri)) {
|
||||
$error = new MessageBag([
|
||||
'title' => '错误',
|
||||
'message' => '外链类型必须添加外链地址',
|
||||
]);
|
||||
|
||||
return back()->withInput()->with(compact('error'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user