Users.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace App\Http\Admin;
  3. use AdminColumn;
  4. use AdminColumnEditable;
  5. use AdminDisplay;
  6. use AdminForm;
  7. use AdminFormElement;
  8. use AdminSection;
  9. use App\Location;
  10. use App\User;
  11. use App\Watcher;
  12. use Illuminate\Database\Eloquent\Model;
  13. use Illuminate\Support\Facades\Auth;
  14. use Illuminate\Support\Facades\Log;
  15. use SleepingOwl\Admin\Contracts\Display\DisplayInterface;
  16. use SleepingOwl\Admin\Contracts\Form\FormInterface;
  17. use SleepingOwl\Admin\Contracts\Initializable;
  18. use SleepingOwl\Admin\Form\Buttons\Cancel;
  19. use SleepingOwl\Admin\Form\Buttons\Save;
  20. use SleepingOwl\Admin\Form\FormElements;
  21. use SleepingOwl\Admin\Section;
  22. /**
  23. * Class Users
  24. *
  25. * @property \App\User $model
  26. *
  27. * @see http://sleepingowladmin.ru/docs/model_configuration_section
  28. */
  29. class Users extends Section implements Initializable
  30. {
  31. /**
  32. * @see http://sleepingowladmin.ru/docs/model_configuration#ограничение-прав-доступа
  33. *
  34. * @var bool
  35. */
  36. protected $checkAccess = false;
  37. protected $redirect = ['edit' => 'display', 'create' => 'display'];
  38. //protected $model = User::class;
  39. /**
  40. * @var string
  41. */
  42. protected $title;
  43. public function initialize()
  44. {
  45. $this->creating(function ($config, Model $model) {
  46. });
  47. }
  48. /**
  49. * @var string
  50. */
  51. protected $alias;
  52. /**
  53. * @return DisplayInterface
  54. */
  55. public function onDisplay()
  56. {
  57. $form = AdminDisplay::datatablesAsync()->setDisplaySearch(true)
  58. ->setOrder([[0, 'desc']])
  59. ->setHtmlAttribute('class', 'table-primary')
  60. ->setColumns(
  61. AdminColumn::link('id', '#')->setWidth('30px'),
  62. AdminColumnEditable::text('name', 'Name')->setWidth('100px'),
  63. AdminColumn::link('email', 'Email')->setWidth('100px')
  64. )->paginate(20);
  65. return $form;
  66. }
  67. /**
  68. * @param int $id
  69. *
  70. * @return FormInterface
  71. */
  72. public function onEdit($id)
  73. {
  74. function product($id) {
  75. $formElement = [];
  76. if($id != null){
  77. $category = User::find($id)->id;
  78. $formElement[] = AdminSection::getModel(Location::class)->fireDisplay(['user_id' => $category]);
  79. }
  80. return $formElement;
  81. };
  82. $formElements = [
  83. AdminFormElement::text('name', 'Name')->required(),
  84. AdminFormElement::text('email', 'Name')->required(),
  85. ];
  86. $tabs = AdminDisplay::tabbed([
  87. 'General' => new FormElements($formElements),
  88. 'Locations' => new FormElements(product($id)),
  89. ]);
  90. $context = empty($id) ? $formElements : $tabs;
  91. $form = AdminForm::panel();
  92. $form->addBody($context);
  93. $form->getButtons()->setButtons([
  94. 'save' => new Save(),
  95. 'cancel' => new Cancel(),
  96. ]);
  97. return $form;
  98. }
  99. /**
  100. * @return FormInterface
  101. */
  102. public function onCreate()
  103. {
  104. return $this->onEdit(null);
  105. }
  106. /**
  107. * @return void
  108. */
  109. public function onDelete($id)
  110. {
  111. // remove if unused
  112. }
  113. /**
  114. * @return void
  115. */
  116. public function onRestore($id)
  117. {
  118. // remove if unused
  119. }
  120. }