LeaveController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\Leave;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. class LeaveController extends AdminController
  9. {
  10. /**
  11. * Make a grid builder.
  12. *
  13. * @return Grid
  14. */
  15. protected function grid()
  16. {
  17. return Grid::make(new Leave(), function (Grid $grid) {
  18. $grid->column('student_id')->using(config('map.students'));
  19. $grid->column('leave_type')->using(config('map.leave_type'));
  20. $grid->column('reason');
  21. $grid->column('start_time');
  22. $grid->column('end_time');
  23. $grid->disableEditButton();
  24. $grid->filter(function (Grid\Filter $filter) {
  25. $filter->panel();
  26. $filter->date('created_at')->datetime()->width(4);
  27. $filter->equal('student_id','输入/选择学生')->select(config('map.students'))->width(4);
  28. });
  29. });
  30. }
  31. /**
  32. * Make a show builder.
  33. *
  34. * @param mixed $id
  35. *
  36. * @return Show
  37. */
  38. protected function detail($id)
  39. {
  40. return Show::make($id, new Leave(), function (Show $show) {
  41. $show->row(function (Show\Row $show) {
  42. $show->field('content','请假详情')
  43. ->width(8)
  44. ->unescape()
  45. ->as(function () {
  46. $html = '';
  47. $html .= '<div style="text-align:left">';
  48. $html .= '<div style="margin-top:5px">请假人:' . config('map.students')[$this->student_id] . '</div>';
  49. $html .= '<div style="margin-top:5px">请假原因:' . $this->reason . '</div>';
  50. $html .= '<div style="margin-top:5px">请假类型:' . config('map.leave_type')[$this->leave_type] . '</div>';
  51. $html .= '<div style="margin-top:5px">开始时间:' . $this->start_time . '</div>';
  52. $html .= '<div style="margin-top:5px">结束时间:' . $this->end_time . '</div>';
  53. $html .= '</div>';
  54. return $html;
  55. });
  56. });
  57. });
  58. }
  59. /**
  60. * Make a form builder.
  61. *
  62. * @return Form
  63. */
  64. protected function form()
  65. {
  66. return Form::make(new Leave(), function (Form $form) {
  67. $form->display('id');
  68. $form->text('student_id');
  69. $form->text('reason');
  70. $form->text('start_time');
  71. $form->text('end_time');
  72. $form->display('created_at');
  73. $form->display('updated_at');
  74. });
  75. }
  76. }