ReportLogController.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\ReportLog;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. class ReportLogController extends AdminController
  9. {
  10. /**
  11. * Make a grid builder.
  12. *
  13. * @return Grid
  14. */
  15. protected function grid()
  16. {
  17. return Grid::make(new ReportLog(), function (Grid $grid) {
  18. $grid->model()->with(['user:id,name,avatar,company_name','product:id,name,image','report:id,title']);
  19. $grid->column('id')->sortable();
  20. $grid->column('user_id')->display(function (){
  21. $str = "";
  22. if(!empty($this->user)){
  23. $str .= "<div style='margin-right:10px;display: flex;align-items: center'>";
  24. $str .= '<img data-action="preview-img" src="' . $this->user->avatar . '" style="height:50px;width:50px;cursor:pointer;margin-right:10px;" class="img img-thumbnail">';
  25. $str .= '<div>';
  26. $str .= '<p style="margin-bottom: 5px">' . $this->user->name . '</p>';
  27. $str .= "</div>";
  28. $str .= "</div>";
  29. }
  30. return $str;
  31. });
  32. $grid->column('product_id')->display(function (){
  33. $str = "";
  34. if(!empty($this->product)){
  35. $str .= "<div style='margin-right:10px;display: flex;align-items: center'>";
  36. $str .= '<img data-action="preview-img" src="' . $this->product->image . '" style="height:50px;width:50px;cursor:pointer;margin-right:10px;" class="img img-thumbnail">';
  37. $str .= '<div>';
  38. $str .= '<p style="margin-bottom: 5px">' . $this->product->name . '</p>';
  39. $str .= "</div>";
  40. $str .= "</div>";
  41. }
  42. return $str;
  43. });
  44. $grid->column('report_id')->display(function (){
  45. return $this->report->title;
  46. });
  47. $grid->column('created_at');
  48. $grid->disableCreateButton();
  49. $grid->filter(function (Grid\Filter $filter) {
  50. $filter->panel();
  51. $filter->like('id')->width(4);
  52. });
  53. });
  54. }
  55. /**
  56. * Make a show builder.
  57. *
  58. * @param mixed $id
  59. *
  60. * @return Show
  61. */
  62. protected function detail($id)
  63. {
  64. return Show::make($id, new ReportLog(), function (Show $show) {
  65. $show->field('id');
  66. $show->field('user_id');
  67. $show->field('product_id');
  68. $show->field('report_id');
  69. $show->field('created_at');
  70. $show->field('updated_at');
  71. });
  72. }
  73. /**
  74. * Make a form builder.
  75. *
  76. * @return Form
  77. */
  78. protected function form()
  79. {
  80. return Form::make(new ReportLog(), function (Form $form) {
  81. $form->display('id');
  82. $form->text('user_id');
  83. $form->text('product_id');
  84. $form->text('report_id');
  85. $form->display('created_at');
  86. $form->display('updated_at');
  87. });
  88. }
  89. }