CommunityNotices.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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->column('id', __('Id'))->sortable();
  28. $grid->column('organization.name', __('发放社区'));
  29. $grid->column('title', __('标题'));
  30. $grid->column('type', __('类型'))->using([1=>'社区通告']);
  31. $grid->column('content', __('内容'))->limit(100,'...');
  32. $grid->column('admin_id', __('发布人'))->display(function ($id){
  33. return Administrator::where('id',$id)->value('username');
  34. });
  35. $grid->column('updated_at', __('更新时间'));
  36. $grid->column('created_at', __('创建时间'));
  37. return $grid;
  38. }
  39. /**
  40. * Make a show builder.
  41. *
  42. * @param mixed $id
  43. * @return Show
  44. */
  45. protected function detail($id)
  46. {
  47. $show = new Show(CommunityNotice::findOrFail($id));
  48. return $show;
  49. }
  50. /**
  51. * Make a form builder.
  52. *
  53. * @return Form
  54. */
  55. protected function form()
  56. {
  57. $form = new Form(new CommunityNotice());
  58. $form->text('title', __('标题'));
  59. $form->select('organization_id', __('发放的社区'))->options(Organization::all()->pluck('name','id'));
  60. $form->select('type', __('类型'))->options([1=>'社区端通告']);
  61. $form->editor('content', __('内容'));
  62. $form->submitted(function ($form){
  63. $form->model()->admin_id = Admin::user()->id;
  64. });
  65. return $form;
  66. }
  67. }