AppIndexPicController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\App_index_pic;
  4. use Encore\Admin\Auth\Database\Administrator;
  5. use Encore\Admin\Form;
  6. use Encore\Admin\Grid;
  7. use Encore\Admin\Facades\Admin;
  8. use Encore\Admin\Layout\Content;
  9. use App\Http\Controllers\Controller;
  10. use Encore\Admin\Controllers\ModelForm;
  11. /**
  12. * app首页管理
  13. * Class AppIndexPicController
  14. * @package App\Admin\Controllers
  15. */
  16. class AppIndexPicController extends Controller
  17. {
  18. use ModelForm;
  19. /**
  20. * Index interface.
  21. *
  22. * @return Content
  23. */
  24. public function index()
  25. {
  26. return Admin::content(function (Content $content) {
  27. $content->header('APP首页管理');
  28. $content->description('列表');
  29. $content->body($this->grid());
  30. });
  31. }
  32. /**
  33. * Edit interface.
  34. *
  35. * @param $id
  36. * @return Content
  37. */
  38. public function edit($id)
  39. {
  40. return Admin::content(function (Content $content) use ($id) {
  41. $content->header('APP首页管理');
  42. $content->description('编辑');
  43. $content->body($this->form()->edit($id));
  44. });
  45. }
  46. /**
  47. * Create interface.
  48. *
  49. * @return Content
  50. */
  51. public function create()
  52. {
  53. return Admin::content(function (Content $content) {
  54. $content->header('APP首页管理');
  55. $content->description('新增');
  56. $content->body($this->form());
  57. });
  58. }
  59. /**
  60. * Make a grid builder.
  61. *
  62. * @return Grid
  63. */
  64. protected function grid()
  65. {
  66. return Admin::grid(App_index_pic::class, function (Grid $grid) {
  67. $grid->id('序号')->sortable();
  68. $grid->column('pic', '显示的图片')->display(function ($pic){
  69. return"<img style='heigh:100px;width:100px' src='/uploads/$pic' />";
  70. });
  71. $grid->column('pic_link_url', '跳转的地址')->editable();
  72. $grid->column('create_id', '创建者')->display(function ($value){
  73. $name = Administrator::where('id',$value)->pluck('name')->first();
  74. return $name;
  75. });
  76. $grid->column('update_id', '更新者')->display(function ($value){
  77. $name = Administrator::where('id',$value)->pluck('name')->first();
  78. return $name;
  79. });;
  80. $grid->created_at('创建时间');
  81. $grid->updated_at('修改时间');
  82. $grid->disableExport();
  83. });
  84. }
  85. /**
  86. * Make a form builder.
  87. *
  88. * @return Form
  89. */
  90. protected function form()
  91. {
  92. return Admin::form(App_index_pic::class, function (Form $form) {
  93. $form->display('id', '序号');
  94. $form->image('pic','显示的图片')->uniqueName();
  95. $form->url('pic_link_url','跳转的页面');
  96. $form->display('update_id', '更新者')->with(function ($value){
  97. if($value){
  98. }else{
  99. $value=Admin::user()->id;
  100. }
  101. $name = Administrator::where('id',$value)->pluck('name')->first();
  102. return $name;
  103. });
  104. $form->display('create_id', '创建者')->with(function ($value){
  105. if($value){
  106. }else{
  107. $value=Admin::user()->id;
  108. }
  109. $name = Administrator::where('id',$value)->pluck('name')->first();
  110. return $name;
  111. });
  112. $form->hidden('create_id')->default(Admin::user()->id);
  113. //保存前回调
  114. $form->saving(function (Form $form) {
  115. $form->update_id =Admin::user()->id;
  116. });
  117. $form->display('created_at', '创建时间');
  118. $form->display('updated_at', '更新时间');
  119. });
  120. }
  121. }