ContactController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\Contact;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. class ContactController extends AdminController
  9. {
  10. /**
  11. * Make a grid builder.
  12. *
  13. * @return Grid
  14. */
  15. protected function grid()
  16. {
  17. return Grid::make(new Contact(), function (Grid $grid) {
  18. $grid->column('id')->sortable();
  19. $grid->column('name');
  20. $grid->column('phone_num');
  21. $grid->column('wechat_num');
  22. $grid->column('created_at');
  23. $grid->column('updated_at')->sortable();
  24. $grid->filter(function (Grid\Filter $filter) {
  25. $filter->equal('id');
  26. });
  27. });
  28. }
  29. /**
  30. * Make a show builder.
  31. *
  32. * @param mixed $id
  33. *
  34. * @return Show
  35. */
  36. protected function detail($id)
  37. {
  38. return Show::make($id, new Contact(), function (Show $show) {
  39. $show->field('id');
  40. $show->field('name');
  41. $show->field('phone_num');
  42. $show->field('wechat_num');
  43. $show->field('created_at');
  44. $show->field('updated_at');
  45. });
  46. }
  47. /**
  48. * Make a form builder.
  49. *
  50. * @return Form
  51. */
  52. protected function form()
  53. {
  54. return Form::make(new Contact(), function (Form $form) {
  55. $form->display('id');
  56. $form->text('name');
  57. $form->text('phone_num');
  58. $form->text('wechat_num');
  59. $form->display('created_at');
  60. $form->display('updated_at');
  61. });
  62. }
  63. }