链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.9 KiB

  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\Category;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Layout\Row;
  6. use Dcat\Admin\Layout\Content;
  7. use Dcat\Admin\Tree;
  8. use Dcat\Admin\Controllers\AdminController;
  9. use Dcat\Admin\Show;
  10. class CategoryController extends AdminController
  11. {
  12. public function index(Content $content)
  13. {
  14. return $content->header('分类')
  15. ->body(function (Row $row) {
  16. $tree = new Tree(new Category);
  17. $tree->branch(function ($branch) {
  18. $src = $branch['cover_img_url'];
  19. $logo = "<img src='$src' style='margin-left: 20px; max-width:35px;max-height:35px' class='img'/>";
  20. return "{$branch['id']} - {$branch['title']} $logo";
  21. });
  22. $row->column(12, $tree);
  23. });
  24. }
  25. public function form()
  26. {
  27. return Form::make(new Category(),function (Form $form){
  28. // 只查一级
  29. $parentList = Category::getCategoryArray([['parent_id','=',0]],[0=>'顶级']);
  30. $form->select('parent_id')->default(0)->options($parentList);
  31. $form->text('title');
  32. $form->image('cover_img');
  33. $form->number('sort');
  34. $form->disableResetButton();
  35. $form->disableViewCheck();
  36. $form->disableEditingCheck();
  37. $form->disableCreatingCheck();
  38. });
  39. }
  40. /**
  41. * Make a show builder.
  42. *
  43. * @param mixed $id
  44. *
  45. * @return Show
  46. */
  47. protected function detail($id)
  48. {
  49. return Show::make($id, new Category(), function (Show $show) {
  50. $show->field('parent_id');
  51. $show->field('title');
  52. $show->field('cover_img')->image();
  53. $show->field('sort');
  54. $show->field('status');
  55. });
  56. }
  57. }