CommunityNotices.php 2.2 KB

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