Form.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. <?php
  2. namespace Dcat\Admin\Widgets;
  3. use Closure;
  4. use Dcat\Admin\Admin;
  5. use Dcat\Admin\Contracts\LazyRenderable;
  6. use Dcat\Admin\Exception\RuntimeException;
  7. use Dcat\Admin\Form\Concerns\HandleCascadeFields;
  8. use Dcat\Admin\Form\Concerns\HasLayout;
  9. use Dcat\Admin\Form\Concerns\HasRows;
  10. use Dcat\Admin\Form\Concerns\HasTabs;
  11. use Dcat\Admin\Form\Field;
  12. use Dcat\Admin\Form\Layout;
  13. use Dcat\Admin\Support\Helper;
  14. use Dcat\Admin\Traits\HasAuthorization;
  15. use Dcat\Admin\Traits\HasFormResponse;
  16. use Dcat\Admin\Traits\HasHtmlAttributes;
  17. use Illuminate\Contracts\Support\Arrayable;
  18. use Illuminate\Contracts\Support\Renderable;
  19. use Illuminate\Http\Request;
  20. use Illuminate\Support\Arr;
  21. use Illuminate\Support\Collection;
  22. use Illuminate\Support\Fluent;
  23. use Illuminate\Support\MessageBag;
  24. use Illuminate\Support\Str;
  25. use Illuminate\Support\Traits\Macroable;
  26. use Illuminate\Validation\Validator;
  27. /**
  28. * Class Form.
  29. *
  30. * @method Field\Text text($column, $label = '')
  31. * @method Field\Checkbox checkbox($column, $label = '')
  32. * @method Field\Radio radio($column, $label = '')
  33. * @method Field\Select select($column, $label = '')
  34. * @method Field\MultipleSelect multipleSelect($column, $label = '')
  35. * @method Field\Textarea textarea($column, $label = '')
  36. * @method Field\Hidden hidden($column, $label = '')
  37. * @method Field\Id id($column, $label = '')
  38. * @method Field\Ip ip($column, $label = '')
  39. * @method Field\Url url($column, $label = '')
  40. * @method Field\Email email($column, $label = '')
  41. * @method Field\Mobile mobile($column, $label = '')
  42. * @method Field\Slider slider($column, $label = '')
  43. * @method Field\Map map($latitude, $longitude, $label = '')
  44. * @method Field\Editor editor($column, $label = '')
  45. * @method Field\Date date($column, $label = '')
  46. * @method Field\Datetime datetime($column, $label = '')
  47. * @method Field\Time time($column, $label = '')
  48. * @method Field\Year year($column, $label = '')
  49. * @method Field\Month month($column, $label = '')
  50. * @method Field\DateRange dateRange($start, $end, $label = '')
  51. * @method Field\DateTimeRange datetimeRange($start, $end, $label = '')
  52. * @method Field\TimeRange timeRange($start, $end, $label = '')
  53. * @method Field\Number number($column, $label = '')
  54. * @method Field\Currency currency($column, $label = '')
  55. * @method Field\SwitchField switch($column, $label = '')
  56. * @method Field\Display display($column, $label = '')
  57. * @method Field\Rate rate($column, $label = '')
  58. * @method Field\Divide divider()
  59. * @method Field\Password password($column, $label = '')
  60. * @method Field\Decimal decimal($column, $label = '')
  61. * @method Field\Html html($html, $label = '')
  62. * @method Field\Tags tags($column, $label = '')
  63. * @method Field\Icon icon($column, $label = '')
  64. * @method Field\Embeds embeds($column, $label = '')
  65. * @method Field\Captcha captcha($column, $label = '')
  66. * @method Field\Listbox listbox($column, $label = '')
  67. * @method Field\File file($column, $label = '')
  68. * @method Field\Image image($column, $label = '')
  69. * @method Field\MultipleFile multipleFile($column, $label = '')
  70. * @method Field\MultipleImage multipleImage($column, $label = '')
  71. * @method Field\HasMany hasMany($column, \Closure $callback)
  72. * @method Field\Tree tree($column, $label = '')
  73. * @method Field\Table table($column, $callback)
  74. * @method Field\ListField list($column, $label = '')
  75. * @method Field\Timezone timezone($column, $label = '')
  76. * @method Field\KeyValue keyValue($column, $label = '')
  77. * @method Field\Tel tel($column, $label = '')
  78. * @method Field\Markdown markdown($column, $label = '')
  79. * @method Field\Range range($start, $end, $label = '')
  80. * @method Field\Color color($column, $label = '')
  81. * @method Field\ArrayField array($column, $labelOrCallback, $callback = null)
  82. * @method Field\SelectTable selectTable($column, $label = '')
  83. * @method Field\MultipleSelectTable multipleSelectTable($column, $label = '')
  84. * @method Field\Button button(string $html = null)
  85. */
  86. class Form implements Renderable
  87. {
  88. use HasHtmlAttributes;
  89. use HasAuthorization;
  90. use HandleCascadeFields;
  91. use HasRows;
  92. use HasTabs;
  93. use HasLayout;
  94. use HasFormResponse {
  95. setCurrentUrl as defaultSetCurrentUrl;
  96. }
  97. use Macroable {
  98. __call as macroCall;
  99. }
  100. const REQUEST_NAME = '_form_';
  101. const CURRENT_URL_NAME = '_current_';
  102. const LAZY_PAYLOAD_NAME = '_payload_';
  103. /**
  104. * @var string
  105. */
  106. protected $view = 'admin::widgets.form';
  107. /**
  108. * @var Field[]|Collection
  109. */
  110. protected $fields;
  111. /**
  112. * @var array
  113. */
  114. protected $variables = [];
  115. /**
  116. * @var bool
  117. */
  118. protected $ajax = true;
  119. /**
  120. * @var Fluent
  121. */
  122. protected $data;
  123. /**
  124. * @var mixed
  125. */
  126. protected $primaryKey;
  127. /**
  128. * Available buttons.
  129. *
  130. * @var array
  131. */
  132. protected $buttons = ['reset' => true, 'submit' => true];
  133. /**
  134. * @var bool
  135. */
  136. protected $useFormTag = true;
  137. /**
  138. * @var string
  139. */
  140. protected $elementId;
  141. /**
  142. * @var array
  143. */
  144. protected $width = [
  145. 'label' => 2,
  146. 'field' => 8,
  147. ];
  148. /**
  149. * @var array
  150. */
  151. protected $confirm = [];
  152. /**
  153. * Form constructor.
  154. *
  155. * @param array $data
  156. * @param mixed $key
  157. */
  158. public function __construct($data = [], $key = null)
  159. {
  160. if ($data) {
  161. $this->fill($data);
  162. }
  163. $this->setKey($key);
  164. $this->setUp();
  165. }
  166. protected function setUp()
  167. {
  168. $this->initFields();
  169. $this->initFormAttributes();
  170. $this->initCurrentUrl();
  171. $this->initPayload();
  172. }
  173. /**
  174. * Initialize the form fields.
  175. */
  176. protected function initFields()
  177. {
  178. $this->fields = new Collection();
  179. }
  180. /**
  181. * Initialize the form attributes.
  182. */
  183. protected function initFormAttributes()
  184. {
  185. $this->setHtmlAttribute([
  186. 'method' => 'POST',
  187. 'action' => '',
  188. 'class' => 'form-horizontal',
  189. 'accept-charset' => 'UTF-8',
  190. 'pjax-container' => true,
  191. ]);
  192. }
  193. protected function initCurrentUrl()
  194. {
  195. if ($this instanceof LazyRenderable) {
  196. $this->setCurrentUrl($this->getCurrentUrl());
  197. }
  198. }
  199. protected function initPayload()
  200. {
  201. if ($payload = \request(static::LAZY_PAYLOAD_NAME)) {
  202. $this->payload(json_decode($payload, true) ?? []);
  203. }
  204. }
  205. /**
  206. * Action uri of the form.
  207. *
  208. * @param string $action
  209. *
  210. * @return $this|string
  211. */
  212. public function action($action = null)
  213. {
  214. if ($action === null) {
  215. return $this->getHtmlAttribute('action');
  216. }
  217. return $this->setHtmlAttribute('action', admin_url($action));
  218. }
  219. /**
  220. * Method of the form.
  221. *
  222. * @param string $method
  223. *
  224. * @return $this
  225. */
  226. public function method(string $method = 'POST')
  227. {
  228. return $this->setHtmlAttribute('method', strtoupper($method));
  229. }
  230. /**
  231. * @param string $title
  232. * @param string $content
  233. *
  234. * @return $this
  235. */
  236. public function confirm(?string $title = null, ?string $content = null)
  237. {
  238. $this->confirm['title'] = $title;
  239. $this->confirm['content'] = $content;
  240. return $this;
  241. }
  242. /**
  243. * Set primary key.
  244. *
  245. * @param mixed $value
  246. *
  247. * @return $this
  248. */
  249. public function setKey($value)
  250. {
  251. $this->primaryKey = $value;
  252. return $this;
  253. }
  254. /**
  255. * Get primary key.
  256. *
  257. * @return mixed
  258. */
  259. public function getKey()
  260. {
  261. return $this->primaryKey;
  262. }
  263. /**
  264. * @param array|Arrayable|Closure $data
  265. *
  266. * @return Fluent
  267. */
  268. public function data()
  269. {
  270. if (! $this->data) {
  271. $this->fill([]);
  272. }
  273. return $this->data;
  274. }
  275. /**
  276. * @param array|Arrayable|Closure $data
  277. *
  278. * @return $this
  279. */
  280. public function fill($data)
  281. {
  282. $this->data = new Fluent(Helper::array($data));
  283. return $this;
  284. }
  285. /**
  286. * @return Fluent
  287. */
  288. public function model()
  289. {
  290. return $this->data();
  291. }
  292. /**
  293. * Add a fieldset to form.
  294. *
  295. * @param string $title
  296. * @param Closure $setCallback
  297. *
  298. * @return Field\Fieldset
  299. */
  300. public function fieldset(string $title, Closure $setCallback)
  301. {
  302. $fieldset = new Field\Fieldset();
  303. $this->html($fieldset->start($title))->plain();
  304. $setCallback($this);
  305. $this->html($fieldset->end())->plain();
  306. return $fieldset;
  307. }
  308. /**
  309. * Get specify field.
  310. *
  311. * @param string|Field $name
  312. *
  313. * @return Field|null
  314. */
  315. public function field($name)
  316. {
  317. foreach ($this->fields as $field) {
  318. if (is_array($field->column())) {
  319. return in_array($name, $field->column(), true) ? $field : null;
  320. }
  321. if ($field === $name || $field->column() === $name) {
  322. return $field;
  323. }
  324. }
  325. }
  326. /**
  327. * @return Field[]|Collection
  328. */
  329. public function fields()
  330. {
  331. return $this->fields;
  332. }
  333. /**
  334. * Validate this form fields.
  335. *
  336. * @param Request $request
  337. *
  338. * @return bool|MessageBag
  339. */
  340. public function validate(Request $request)
  341. {
  342. $failedValidators = [];
  343. /** @var \Dcat\Admin\Form\Field $field */
  344. foreach ($this->fields() as $field) {
  345. if (! $validator = $field->getValidator($request->all())) {
  346. continue;
  347. }
  348. if (($validator instanceof Validator) && ! $validator->passes()) {
  349. $failedValidators[] = $validator;
  350. }
  351. }
  352. $message = $this->mergeValidationMessages($failedValidators);
  353. return $message->any() ? $message : false;
  354. }
  355. /**
  356. * Merge validation messages from input validators.
  357. *
  358. * @param \Illuminate\Validation\Validator[] $validators
  359. *
  360. * @return MessageBag
  361. */
  362. protected function mergeValidationMessages($validators)
  363. {
  364. $messageBag = new MessageBag();
  365. foreach ($validators as $validator) {
  366. $messageBag = $messageBag->merge($validator->messages());
  367. }
  368. return $messageBag;
  369. }
  370. /**
  371. * Disable Pjax.
  372. *
  373. * @return $this
  374. */
  375. public function disablePjax()
  376. {
  377. $this->forgetHtmlAttribute('pjax-container');
  378. return $this;
  379. }
  380. /**
  381. * Disable form tag.
  382. *
  383. * @return $this;
  384. */
  385. public function disableFormTag()
  386. {
  387. $this->useFormTag = false;
  388. return $this;
  389. }
  390. /**
  391. * Disable reset button.
  392. *
  393. * @param bool $value
  394. *
  395. * @return $this
  396. */
  397. public function disableResetButton(bool $value = true)
  398. {
  399. $this->buttons['reset'] = ! $value;
  400. return $this;
  401. }
  402. /**
  403. * Disable submit button.
  404. *
  405. * @param bool $value
  406. *
  407. * @return $this
  408. */
  409. public function disableSubmitButton(bool $value = true)
  410. {
  411. $this->buttons['submit'] = ! $value;
  412. return $this;
  413. }
  414. /**
  415. * Set field and label width in current form.
  416. *
  417. * @param int $fieldWidth
  418. * @param int $labelWidth
  419. *
  420. * @return $this
  421. */
  422. public function width($fieldWidth = 8, $labelWidth = 2)
  423. {
  424. $this->width = [
  425. 'label' => $labelWidth,
  426. 'field' => $fieldWidth,
  427. ];
  428. $this->fields->each(function ($field) use ($fieldWidth, $labelWidth) {
  429. /* @var Field $field */
  430. $field->width($fieldWidth, $labelWidth);
  431. });
  432. return $this;
  433. }
  434. /**
  435. * Find field class with given name.
  436. *
  437. * @param string $method
  438. *
  439. * @return bool|string
  440. */
  441. public static function findFieldClass($method)
  442. {
  443. $class = Arr::get(\Dcat\Admin\Form::extensions(), $method);
  444. if (class_exists($class)) {
  445. return $class;
  446. }
  447. return false;
  448. }
  449. /**
  450. * Add a form field to form.
  451. *
  452. * @param Field $field
  453. *
  454. * @return $this
  455. */
  456. public function pushField(Field $field)
  457. {
  458. $this->fields->push($field);
  459. if ($this->layout()->hasColumns()) {
  460. $this->layout()->addField($field);
  461. }
  462. $field->setForm($this);
  463. $field->width($this->width['field'], $this->width['label']);
  464. $this->setFileUploadUrl($field);
  465. $field::requireAssets();
  466. return $this;
  467. }
  468. protected function setFileUploadUrl(Field $field)
  469. {
  470. if ($field instanceof Field\File && method_exists($this, 'form')) {
  471. $formData = [static::REQUEST_NAME => get_called_class()];
  472. $field->url(route(admin_api_route('form.upload')));
  473. $field->deleteUrl(route(admin_api_route('form.destroy-file'), $formData));
  474. $field->withFormData($formData);
  475. }
  476. }
  477. /**
  478. * Get variables for render form.
  479. *
  480. * @return array
  481. */
  482. protected function variables()
  483. {
  484. $this->setHtmlAttribute('id', $this->getElementId());
  485. $this->fillFields($this->model()->toArray());
  486. return array_merge([
  487. 'start' => $this->open(),
  488. 'end' => $this->close(),
  489. 'fields' => $this->fields,
  490. 'method' => $this->getHtmlAttribute('method'),
  491. 'rows' => $this->rows(),
  492. 'layout' => $this->layout(),
  493. 'elementId' => $this->getElementId(),
  494. 'ajax' => $this->ajax,
  495. 'footer' => $this->renderFooter(),
  496. ], $this->variables);
  497. }
  498. /**
  499. * 表单底部内容.
  500. *
  501. * @return string
  502. */
  503. protected function renderFooter()
  504. {
  505. if (empty($this->buttons['reset']) && empty($this->buttons['submit'])) {
  506. return;
  507. }
  508. $buttons = '';
  509. if (! empty($this->buttons['reset'])) {
  510. $reset = trans('admin.reset');
  511. $buttons .= "<button type=\"reset\" class=\"btn btn-white pull-left\"><i class=\"feather icon-rotate-ccw\"></i> {$reset}</button>";
  512. }
  513. if (! empty($this->buttons['submit'])) {
  514. $submit = $this->getSubmitButtonLabel();
  515. $buttons .= "<button type=\"submit\" class=\"btn btn-primary pull-right\"><i class=\"feather icon-save\"></i> {$submit}</button>";
  516. }
  517. return <<<HTML
  518. <div class="box-footer row d-flex">
  519. <div class="col-md-2"> &nbsp;</div>
  520. <div class="col-md-8">{$buttons}</div>
  521. </div>
  522. HTML;
  523. }
  524. /**
  525. * 提交按钮文本.
  526. *
  527. * @return string
  528. */
  529. protected function getSubmitButtonLabel()
  530. {
  531. return trans('admin.submit');
  532. }
  533. /**
  534. * 设置视图变量.
  535. *
  536. * @param array $variables
  537. *
  538. * @return $this
  539. */
  540. public function addVariables(array $variables)
  541. {
  542. $this->variables = array_merge($this->variables, $variables);
  543. return $this;
  544. }
  545. public function fillFields(array $data)
  546. {
  547. foreach ($this->fields as $field) {
  548. $field->fill($data);
  549. }
  550. }
  551. /**
  552. * @return string
  553. */
  554. protected function open()
  555. {
  556. if (! $this->useFormTag) {
  557. return;
  558. }
  559. return <<<HTML
  560. <form {$this->formatHtmlAttributes()}>
  561. HTML;
  562. }
  563. /**
  564. * @return string
  565. */
  566. protected function close()
  567. {
  568. if (! $this->useFormTag) {
  569. return;
  570. }
  571. return '</form>';
  572. }
  573. /**
  574. * Determine if form fields has files.
  575. *
  576. * @return bool
  577. */
  578. public function hasFile()
  579. {
  580. foreach ($this->fields as $field) {
  581. if ($field instanceof Field\File) {
  582. return true;
  583. }
  584. }
  585. return false;
  586. }
  587. /**
  588. * @param $id
  589. *
  590. * @return $this
  591. */
  592. public function setFormId($id)
  593. {
  594. $this->elementId = $id;
  595. return $this;
  596. }
  597. /**
  598. * @return string
  599. */
  600. public function getElementId()
  601. {
  602. return $this->elementId ?: ($this->elementId = 'form-'.Str::random(8));
  603. }
  604. /**
  605. * {@inheritdoc}
  606. */
  607. public function setCurrentUrl($url)
  608. {
  609. if ($this instanceof LazyRenderable) {
  610. $this->payload([static::CURRENT_URL_NAME => $url]);
  611. }
  612. return $this->defaultSetCurrentUrl($url);
  613. }
  614. /**
  615. * @param bool $disable
  616. *
  617. * @return $this
  618. */
  619. public function ajax(bool $value = true)
  620. {
  621. $this->ajax = $value;
  622. return $this;
  623. }
  624. /**
  625. * @return bool
  626. */
  627. public function allowAjaxSubmit()
  628. {
  629. return $this->ajax === true;
  630. }
  631. /**
  632. * @return string|void
  633. */
  634. protected function savedScript()
  635. {
  636. }
  637. /**
  638. * @return string|void
  639. */
  640. protected function errorScript()
  641. {
  642. }
  643. /**
  644. * @param array $input
  645. *
  646. * @return array
  647. */
  648. public function sanitize(array $input)
  649. {
  650. Arr::forget($input, [static::REQUEST_NAME, '_token', static::CURRENT_URL_NAME]);
  651. return $this->prepareInput($input);
  652. }
  653. public function prepareInput(array $input)
  654. {
  655. Helper::prepareHasOneRelation($this->fields, $input);
  656. foreach ($input as $column => $value) {
  657. $field = $this->field($column);
  658. if (! $field instanceof Field) {
  659. unset($input[$column]);
  660. continue;
  661. }
  662. $input[$column] = $field->prepare($value);
  663. }
  664. $prepared = [];
  665. foreach ($input as $key => $value) {
  666. Arr::set($prepared, $key, $value);
  667. }
  668. return $prepared;
  669. }
  670. protected function prepareForm()
  671. {
  672. if (method_exists($this, 'form')) {
  673. $this->form();
  674. }
  675. if (! $this->data && method_exists($this, 'default')) {
  676. $data = $this->default();
  677. if (is_array($data)) {
  678. $this->fill($data);
  679. }
  680. }
  681. }
  682. protected function prepareHandler()
  683. {
  684. if (method_exists($this, 'handle')) {
  685. $addHiddenFields = function () {
  686. $this->method('POST');
  687. $this->action(route(admin_api_route('form')));
  688. $this->hidden(static::REQUEST_NAME)->default(get_called_class());
  689. $this->hidden(static::CURRENT_URL_NAME)->default($this->getCurrentUrl());
  690. if (! empty($this->payload) && is_array($this->payload)) {
  691. $this->hidden(static::LAZY_PAYLOAD_NAME)->default(json_encode($this->payload));
  692. }
  693. };
  694. $this->layout()->hasColumns() ? $this->column(1, $addHiddenFields) : $addHiddenFields();
  695. }
  696. }
  697. /**
  698. * Render the form.
  699. *
  700. * @return string
  701. */
  702. public function render()
  703. {
  704. $this->prepareForm();
  705. $this->prepareHandler();
  706. if ($this->allowAjaxSubmit()) {
  707. $this->addAjaxScript();
  708. }
  709. $tabObj = $this->getTab();
  710. if (! $tabObj->isEmpty()) {
  711. $tabObj->addScript();
  712. }
  713. $this->addVariables([
  714. 'tabObj' => $tabObj,
  715. ]);
  716. return view($this->view, $this->variables())->render();
  717. }
  718. protected function addAjaxScript()
  719. {
  720. $confirm = admin_javascript_json($this->confirm);
  721. Admin::script(
  722. <<<JS
  723. $('#{$this->getElementId()}').form({
  724. validate: true,
  725. confirm: {$confirm},
  726. success: function (data) {
  727. {$this->savedScript()}
  728. },
  729. error: function (response) {
  730. {$this->errorScript()}
  731. }
  732. });
  733. JS
  734. );
  735. }
  736. /**
  737. * Generate a Field object and add to form builder if Field exists.
  738. *
  739. * @param string $method
  740. * @param array $arguments
  741. *
  742. * @return Field|null
  743. */
  744. public function __call($method, $arguments)
  745. {
  746. if ($className = static::findFieldClass($method)) {
  747. $name = Arr::get($arguments, 0, '');
  748. $element = new $className($name, array_slice($arguments, 1));
  749. $this->pushField($element);
  750. return $element;
  751. }
  752. if (static::hasMacro($method)) {
  753. return $this->macroCall($method, $arguments);
  754. }
  755. throw new RuntimeException("Field [{$method}] does not exist.");
  756. }
  757. /**
  758. * Output as string.
  759. *
  760. * @return string
  761. */
  762. public function __toString()
  763. {
  764. return $this->render();
  765. }
  766. /**
  767. * @param mixed ...$params
  768. *
  769. * @return $this
  770. */
  771. public static function make(...$params)
  772. {
  773. return new static(...$params);
  774. }
  775. }