DocumentController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\Document;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. class DocumentController extends AdminController
  9. {
  10. /**
  11. * Make a grid builder.
  12. *
  13. * @return Grid
  14. */
  15. protected function grid()
  16. {
  17. $grid = new Grid(new Document());
  18. $grid->model()->orderBy('id','desc');
  19. $grid->column('id')->sortable();
  20. $grid->column('title');
  21. // $grid->column('created_at');
  22. $grid->column('updated_at')->sortable();
  23. $grid->filter(function (Grid\Filter $filter) {
  24. $filter->equal('id');
  25. $filter->like('title','标题');
  26. });
  27. //操作管理
  28. $grid->actions(function (Grid\Displayers\Actions $actions) {
  29. if ($actions->row->id == 1 || $actions->row->id == 2) {
  30. $actions->disableDelete();
  31. }
  32. });
  33. return $grid;
  34. }
  35. /**
  36. * Make a show builder.
  37. *
  38. * @param mixed $id
  39. *
  40. * @return Show
  41. */
  42. protected function detail($id)
  43. {
  44. return Show::make($id, new Document(), function (Show $show) {
  45. $show->field('id');
  46. $show->field('title');
  47. $show->field('content')->unescape();
  48. $show->field('created_at');
  49. $show->field('updated_at');
  50. });
  51. }
  52. /**
  53. * Make a form builder.
  54. *
  55. * @return Form
  56. */
  57. protected function form()
  58. {
  59. return Form::make(new Document(), function (Form $form) {
  60. $form->display('id');
  61. $form->text('title');
  62. $form->editor('content');
  63. $form->display('created_at');
  64. $form->display('updated_at');
  65. });
  66. }
  67. }