CommunityNotices.php 2.1 KB

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