NoticeController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Actions\Notice\NoticeSend;
  4. use App\Models\Notice;
  5. use App\Models\User;
  6. use Dcat\Admin\Form;
  7. use Dcat\Admin\Grid;
  8. use Dcat\Admin\Show;
  9. use Dcat\Admin\Http\Controllers\AdminController;
  10. use Faker\Factory;
  11. class NoticeController extends AdminController
  12. {
  13. /**
  14. * Make a grid builder.
  15. *
  16. * @return Grid
  17. */
  18. protected function grid()
  19. {
  20. $grid = new Grid(new Notice());
  21. $grid->model()->orderBy('id','desc');
  22. $grid->column('id')->sortable();
  23. $grid->column('title');
  24. $grid->column('content')->limit(60);
  25. $grid->column('users')->using(['全部用户','男性用户','女性用户'])->label(['success','primary','warning']);
  26. $grid->column('created_at');
  27. //$grid->column('updated_at')->sortable();
  28. $grid->filter(function (Grid\Filter $filter) {
  29. $filter->equal('id');
  30. });
  31. //操作管理
  32. // $grid->actions(function (Grid\Displayers\Actions $actions) {
  33. // $actions->append(new NoticeSend(User::class));
  34. // });
  35. return $grid;
  36. }
  37. /**
  38. * Make a show builder.
  39. *
  40. * @param mixed $id
  41. *
  42. * @return Show
  43. */
  44. protected function detail($id)
  45. {
  46. return Show::make($id, new Notice(), function (Show $show) {
  47. $show->field('id');
  48. $show->field('title');
  49. $show->field('content')->unescape();
  50. $show->field('users')->using(['全部用户','男性用户','女性用户']);
  51. $show->field('created_at');
  52. $show->field('updated_at');
  53. });
  54. }
  55. /**
  56. * Make a form builder.
  57. *
  58. * @return Form
  59. */
  60. protected function form()
  61. {
  62. return Form::make(new Notice(), function (Form $form) {
  63. $form->display('id');
  64. $form->text('title');
  65. $form->editor('content');
  66. $form->radio('users')->options([0=>'全部用户',1=>'男性用户',2=>"女性用户"])->default(0);
  67. $form->display('created_at');
  68. $form->display('updated_at');
  69. });
  70. }
  71. }