CommunityNotices.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Admin\Controllers\CommunityNotice;
  3. use App\Models\CommunityNotice;
  4. use Encore\Admin\Auth\Database\Administrator;
  5. use Encore\Admin\Controllers\AdminController;
  6. use Encore\Admin\Facades\Admin;
  7. use Encore\Admin\Form;
  8. use Encore\Admin\Grid;
  9. use Encore\Admin\Show;
  10. class CommunityNotices extends AdminController
  11. {
  12. /**
  13. * Title for current resource.
  14. *
  15. * @var string
  16. */
  17. protected $title = '社区端通告';
  18. /**
  19. * Make a grid builder.
  20. *
  21. * @return Grid
  22. */
  23. protected function grid()
  24. {
  25. $grid = new Grid(new CommunityNotice());
  26. $grid->column('id', __('Id'))->sortable();
  27. $grid->column('title', __('标题'));
  28. $grid->column('type', __('类型'))->using([1=>'社区通告']);
  29. $grid->column('content', __('内容'))->limit(100,'...');
  30. $grid->column('admin_id', __('发布人'))->display(function ($id){
  31. return Administrator::where('id',$id)->value('username');
  32. });
  33. $grid->column('updated_at', __('更新时间'));
  34. $grid->column('created_at', __('创建时间'));
  35. return $grid;
  36. }
  37. /**
  38. * Make a show builder.
  39. *
  40. * @param mixed $id
  41. * @return Show
  42. */
  43. protected function detail($id)
  44. {
  45. $show = new Show(CommunityNotice::findOrFail($id));
  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 CommunityNotice());
  56. $form->text('title', __('标题'));
  57. $form->select('type', __('类型'))->options([1=>'社区端通告']);
  58. $form->editor('content', __('内容'));
  59. $form->submitted(function ($form){
  60. $form->model()->admin_id = Admin::user()->id;
  61. });
  62. return $form;
  63. }
  64. }