header('分类')
->body(function (Row $row) {
$tree = new Tree(new Category);
$tree->branch(function ($branch) {
// 查询分类ssdb
$ssdb = new SsdbClient();
$category = $ssdb->client()->hgetall('applet_index_category');
$select = array_keys($category);
$src = $branch['cover_img_url'];
$logo = "
";
$actions = '';
$actions = (in_array($branch['id'],$select)) ?'在首页显示'.'【'.$branch['sort'].'】' :$actions;
return "{$branch['id']} - {$branch['title']} $logo $actions ";
});
$tree->tools(function (Tree\Tools $tools) {
$tools->add(new CategoryTie());
});
$row->column(12, $tree);
});
}
public function form()
{
return Form::make(new Category(),function (Form $form){
// 只查一级
$parentList = Category::getArray([['parent_id','=',0]],['顶级'=>0]);
$form->select('parent_id')->default(0)->options($parentList);
$form->text('title')->required();
$form->image('cover_img')->autoUpload()->required()->uniqueName();
$form->number('sort');
$form->radio('status')->options([0 => '禁用', 1 => '正常']);
$form->disableResetButton();
$form->disableViewCheck();
$form->disableEditingCheck();
$form->disableCreatingCheck();
});
}
public function categoryTieForms(Content $content)
{
return $content
->title('绑定分类到首页')
->body(new Card(new CategoryTieForm()));
}
/**
* Make a show builder.
*
* @param mixed $id
*
* @return Show
*/
protected function detail($id)
{
return Show::make($id, new Category(), function (Show $show) {
$show->field('parent_id');
$show->field('title');
$show->field('cover_img')->image();
$show->field('sort');
$show->field('status');
});
}
}