MsgController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\Msg;
  4. use App\Models\User;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. class MsgController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(new Msg(), function (Grid $grid) {
  19. $grid->model()->orderByDesc("id");
  20. $grid->column('id')->sortable();
  21. // $grid->column('type');
  22. // $grid->column('user_id');
  23. // $grid->column('to_user_id');
  24. $grid->column('title');
  25. $grid->column('content');
  26. $grid->column('created_at');
  27. $grid->column('updated_at')->sortable();
  28. $grid->actions(function (Grid\Displayers\Actions $actions) {
  29. $actions->disableEdit();
  30. $actions->disableView();
  31. });
  32. $grid->filter(function (Grid\Filter $filter) {
  33. $filter->panel();
  34. $filter->like('title')->width(4);
  35. $filter->like('content')->width(4);
  36. });
  37. });
  38. }
  39. /**
  40. * Make a show builder.
  41. *
  42. * @param mixed $id
  43. *
  44. * @return Show
  45. */
  46. protected function detail($id)
  47. {
  48. return Show::make($id, new Msg(), function (Show $show) {
  49. $show->field('id');
  50. $show->field('type');
  51. $show->field('user_id');
  52. $show->field('to_user_id');
  53. $show->field('title');
  54. $show->field('content');
  55. $show->field('created_at');
  56. $show->field('updated_at');
  57. });
  58. }
  59. /**
  60. * Make a form builder.
  61. *
  62. * @return Form
  63. */
  64. protected function form()
  65. {
  66. return Form::make(new Msg(), function (Form $form) {
  67. $form->display('id');
  68. $form->hidden('type')->default(6);
  69. $form->hidden('user_id')->default(0);
  70. $form->select('to_user_id')->options(function ($item){
  71. return User::pluck('name','id');
  72. });
  73. $form->hidden('title')->default("系统通知");
  74. $form->textarea('content');
  75. $form->display('created_at');
  76. $form->display('updated_at');
  77. });
  78. }
  79. }