BannerController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use Encore\Admin\Controllers\AdminController;
  4. use Encore\Admin\Form;
  5. use Encore\Admin\Grid;
  6. use Encore\Admin\Show;
  7. use App\Models\Banner;
  8. class BannerController extends AdminController
  9. {
  10. /**
  11. * Title for current resource.
  12. *
  13. * @var string
  14. */
  15. protected $title = 'Banner 管理';
  16. /**
  17. * Make a grid builder.
  18. *
  19. * @return Grid
  20. */
  21. protected function grid()
  22. {
  23. $grid = new Grid(new Banner);
  24. $grid->column('id', __('ID'))->sortable();
  25. $grid->column('name', __('位置名称'));
  26. $grid->column('local_id', __('位置'))->display(function ($localId) {
  27. return isset(Banner::$localMap[$localId])?Banner::$localMap[$localId]:"未知";
  28. });
  29. $grid->column('rank', __('排序(越大越靠前)'))->sortable();
  30. $grid->column('created_at', __('创建时间'));
  31. $grid->column('updated_at', __('更新时间'));
  32. return $grid;
  33. }
  34. /**
  35. * Make a show builder.
  36. *
  37. * @param mixed $id
  38. * @return Show
  39. */
  40. protected function detail($id)
  41. {
  42. $show = new Show(Banner::findOrFail($id));
  43. $show->field('id', __('ID'));
  44. $show->field('created_at', __('Created at'));
  45. $show->field('updated_at', __('Updated at'));
  46. return $show;
  47. }
  48. /**
  49. * Make a form builder.
  50. *
  51. * @return Form
  52. */
  53. protected function form()
  54. {
  55. $form = new Form(new Banner);
  56. $form->display('id', __('ID'));
  57. $form->select('local_id', __('位置'))->options(Banner::$localMap)->rules('required');
  58. $form->text('name', __('名称'))->rules('required');
  59. $form->image('pic', __('图片'))->uniqueName()->move('pics/'.date('Y').'/'.date('m'))->rules('required');
  60. $form->text('url', __('链接地址'))->rules('required');
  61. $form->number('rank', __('排序(越大越靠前)'))->default(0);
  62. return $form;
  63. }
  64. }