Grid.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. <?php
  2. namespace Dcat\Admin;
  3. use Closure;
  4. use Dcat\Admin\Contracts\Repository;
  5. use Dcat\Admin\Grid\Column;
  6. use Dcat\Admin\Grid\Concerns;
  7. use Dcat\Admin\Grid\Model;
  8. use Dcat\Admin\Grid\Row;
  9. use Dcat\Admin\Grid\Tools;
  10. use Dcat\Admin\Support\Helper;
  11. use Dcat\Admin\Traits\HasBuilderEvents;
  12. use Dcat\Admin\Traits\HasVariables;
  13. use Illuminate\Contracts\Support\Renderable;
  14. use Illuminate\Database\Eloquent\Builder;
  15. use Illuminate\Support\Collection;
  16. use Illuminate\Support\Traits\Macroable;
  17. class Grid
  18. {
  19. use HasBuilderEvents;
  20. use HasVariables;
  21. use Concerns\HasEvents;
  22. use Concerns\HasNames;
  23. use Concerns\HasFilter;
  24. use Concerns\HasTools;
  25. use Concerns\HasActions;
  26. use Concerns\HasPaginator;
  27. use Concerns\HasExporter;
  28. use Concerns\HasComplexHeaders;
  29. use Concerns\HasSelector;
  30. use Concerns\HasQuickCreate;
  31. use Concerns\HasQuickSearch;
  32. use Concerns\CanFixColumns;
  33. use Concerns\CanHidesColumns;
  34. use Macroable {
  35. __call as macroCall;
  36. }
  37. const CREATE_MODE_DEFAULT = 'default';
  38. const CREATE_MODE_DIALOG = 'dialog';
  39. /**
  40. * The grid data model instance.
  41. *
  42. * @var \Dcat\Admin\Grid\Model
  43. */
  44. protected $model;
  45. /**
  46. * Collection of grid columns.
  47. *
  48. * @var \Illuminate\Support\Collection
  49. */
  50. protected $columns;
  51. /**
  52. * Collection of all grid columns.
  53. *
  54. * @var \Illuminate\Support\Collection
  55. */
  56. protected $allColumns;
  57. /**
  58. * Collection of all data rows.
  59. *
  60. * @var \Illuminate\Support\Collection
  61. */
  62. protected $rows;
  63. /**
  64. * @var array
  65. */
  66. protected $rowsCallbacks = [];
  67. /**
  68. * All column names of the grid.
  69. *
  70. * @var array
  71. */
  72. protected $columnNames = [];
  73. /**
  74. * Grid builder.
  75. *
  76. * @var \Closure
  77. */
  78. protected $builder;
  79. /**
  80. * Mark if the grid is built.
  81. *
  82. * @var bool
  83. */
  84. protected $built = false;
  85. /**
  86. * Resource path of the grid.
  87. *
  88. * @var
  89. */
  90. protected $resourcePath;
  91. /**
  92. * Default primary key name.
  93. *
  94. * @var string|array
  95. */
  96. protected $keyName;
  97. /**
  98. * View for grid to render.
  99. *
  100. * @var string
  101. */
  102. protected $view = 'admin::grid.table';
  103. /**
  104. * @var Closure[]
  105. */
  106. protected $header = [];
  107. /**
  108. * @var Closure[]
  109. */
  110. protected $footer = [];
  111. /**
  112. * @var Closure
  113. */
  114. protected $wrapper;
  115. /**
  116. * @var bool
  117. */
  118. protected $addNumberColumn = false;
  119. /**
  120. * @var string
  121. */
  122. protected $tableId = 'grid-table';
  123. /**
  124. * @var Grid\Tools\RowSelector
  125. */
  126. protected $rowSelector;
  127. /**
  128. * Options for grid.
  129. *
  130. * @var array
  131. */
  132. protected $options = [
  133. 'pagination' => true,
  134. 'filter' => true,
  135. 'actions' => true,
  136. 'quick_edit_button' => false,
  137. 'edit_button' => true,
  138. 'view_button' => true,
  139. 'delete_button' => true,
  140. 'row_selector' => true,
  141. 'create_button' => true,
  142. 'bordered' => false,
  143. 'table_collapse' => true,
  144. 'table_scrollbar' => false,
  145. 'toolbar' => true,
  146. 'create_mode' => self::CREATE_MODE_DEFAULT,
  147. 'dialog_form_area' => ['700px', '670px'],
  148. 'table_class' => ['table', 'custom-data-table', 'data-table'],
  149. 'scrollbar_x' => false,
  150. ];
  151. /**
  152. * @var \Illuminate\Http\Request
  153. */
  154. protected $request;
  155. /**
  156. * @var bool
  157. */
  158. protected $show = true;
  159. /**
  160. * Create a new grid instance.
  161. *
  162. * Grid constructor.
  163. *
  164. * @param Repository|\Illuminate\Database\Eloquent\Model|Builder|null $repository
  165. * @param null|\Closure $builder
  166. */
  167. public function __construct($repository = null, ?\Closure $builder = null, $request = null)
  168. {
  169. $this->model = new Model(request(), $repository);
  170. $this->columns = new Collection();
  171. $this->allColumns = new Collection();
  172. $this->rows = new Collection();
  173. $this->builder = $builder;
  174. $this->request = $request ?: request();
  175. $this->resourcePath = url($this->request->getPathInfo());
  176. if ($repository = $this->model->repository()) {
  177. $this->setKeyName($repository->getKeyName());
  178. }
  179. $this->model->setGrid($this);
  180. $this->setUpTools();
  181. $this->setUpFilter();
  182. $this->callResolving();
  183. }
  184. /**
  185. * Get table ID.
  186. *
  187. * @return string
  188. */
  189. public function getTableId()
  190. {
  191. return $this->tableId;
  192. }
  193. /**
  194. * Set primary key name.
  195. *
  196. * @param string|array $name
  197. *
  198. * @return $this
  199. */
  200. public function setKeyName($name)
  201. {
  202. $this->keyName = $name;
  203. return $this;
  204. }
  205. /**
  206. * Get or set primary key name.
  207. *
  208. * @return string|array
  209. */
  210. public function getKeyName()
  211. {
  212. return $this->keyName ?: 'id';
  213. }
  214. /**
  215. * Add column to Grid.
  216. *
  217. * @param string $name
  218. * @param string $label
  219. *
  220. * @return Column
  221. */
  222. public function column($name, $label = '')
  223. {
  224. return $this->addColumn($name, $label);
  225. }
  226. /**
  227. * Add number column.
  228. *
  229. * @param null|string $label
  230. *
  231. * @return Column
  232. */
  233. public function number(?string $label = null)
  234. {
  235. return $this->addColumn('#', $label ?: '#');
  236. }
  237. /**
  238. * Batch add column to grid.
  239. *
  240. * @example
  241. * 1.$grid->columns(['name' => 'Name', 'email' => 'Email' ...]);
  242. * 2.$grid->columns('name', 'email' ...)
  243. *
  244. * @param array $columns
  245. *
  246. * @return Collection|Column[]|void
  247. */
  248. public function columns($columns = null)
  249. {
  250. if ($columns === null) {
  251. return $this->columns;
  252. }
  253. if (func_num_args() == 1 && is_array($columns)) {
  254. foreach ($columns as $column => $label) {
  255. $this->column($column, $label);
  256. }
  257. return;
  258. }
  259. foreach (func_get_args() as $column) {
  260. $this->column($column);
  261. }
  262. }
  263. /**
  264. * @return Collection|Column[]
  265. */
  266. public function allColumns()
  267. {
  268. return $this->allColumns;
  269. }
  270. /**
  271. * 删除列.
  272. *
  273. * @param string|Column $column
  274. *
  275. * @return $this
  276. */
  277. public function dropColumn($column)
  278. {
  279. if ($column instanceof Column) {
  280. $column = $column->getName();
  281. }
  282. $this->columns->offsetUnset($column);
  283. $this->allColumns->offsetUnset($column);
  284. return $this;
  285. }
  286. /**
  287. * Add column to grid.
  288. *
  289. * @param string $field
  290. * @param string $label
  291. *
  292. * @return Column
  293. */
  294. protected function addColumn($field = '', $label = '')
  295. {
  296. $column = $this->newColumn($field, $label);
  297. $this->columns->put($field, $column);
  298. $this->allColumns->put($field, $column);
  299. return $column;
  300. }
  301. /**
  302. * @param string $field
  303. * @param string $label
  304. *
  305. * @return Column
  306. */
  307. public function prependColumn($field = '', $label = '')
  308. {
  309. $column = $this->newColumn($field, $label);
  310. $this->columns->prepend($column, $field);
  311. $this->allColumns->prepend($column, $field);
  312. return $column;
  313. }
  314. /**
  315. * @param string $field
  316. * @param string $label
  317. *
  318. * @return Column
  319. */
  320. public function newColumn($field = '', $label = '')
  321. {
  322. $column = new Column($field, $label);
  323. $column->setGrid($this);
  324. return $column;
  325. }
  326. /**
  327. * Get Grid model.
  328. *
  329. * @return Model
  330. */
  331. public function model()
  332. {
  333. return $this->model;
  334. }
  335. /**
  336. * @return array
  337. */
  338. public function getColumnNames()
  339. {
  340. return $this->columnNames;
  341. }
  342. /**
  343. * Apply column filter to grid query.
  344. */
  345. protected function applyColumnFilter()
  346. {
  347. $this->columns->each->bindFilterQuery($this->model());
  348. }
  349. /**
  350. * @param string|array $class
  351. *
  352. * @return $this
  353. */
  354. public function addTableClass($class)
  355. {
  356. $this->options['table_class'] = array_merge((array) $this->options['table_class'], (array) $class);
  357. return $this;
  358. }
  359. public function formatTableClass()
  360. {
  361. if ($this->options['bordered']) {
  362. $this->addTableClass(['table-bordered', 'complex-headers', 'data-table']);
  363. }
  364. return implode(' ', array_unique((array) $this->options['table_class']));
  365. }
  366. /**
  367. * Build the grid.
  368. *
  369. * @return void
  370. */
  371. public function build()
  372. {
  373. if ($this->built) {
  374. return;
  375. }
  376. $collection = clone $this->processFilter();
  377. $this->prependRowSelectorColumn();
  378. $this->appendActionsColumn();
  379. Column::setOriginalGridModels($collection);
  380. $this->columns->map(function (Column $column) use (&$collection) {
  381. $column->fill($collection);
  382. $this->columnNames[] = $column->getName();
  383. });
  384. $this->buildRows($collection);
  385. $this->sortHeaders();
  386. }
  387. /**
  388. * @return void
  389. */
  390. public function callBuilder()
  391. {
  392. if ($this->builder && ! $this->built) {
  393. call_user_func($this->builder, $this);
  394. }
  395. $this->built = true;
  396. }
  397. /**
  398. * Build the grid rows.
  399. *
  400. * @param Collection $data
  401. *
  402. * @return void
  403. */
  404. protected function buildRows($data)
  405. {
  406. $this->rows = $data->map(function ($row) {
  407. return new Row($this, $row);
  408. });
  409. foreach ($this->rowsCallbacks as $callback) {
  410. $callback($this->rows);
  411. }
  412. }
  413. /**
  414. * Set grid row callback function.
  415. *
  416. * @return Collection|$this
  417. */
  418. public function rows(\Closure $callback = null)
  419. {
  420. if ($callback) {
  421. $this->rowsCallbacks[] = $callback;
  422. return $this;
  423. }
  424. return $this->rows;
  425. }
  426. /**
  427. * Get create url.
  428. *
  429. * @return string
  430. */
  431. public function getCreateUrl()
  432. {
  433. $queryString = '';
  434. if ($constraints = $this->model()->getConstraints()) {
  435. $queryString = http_build_query($constraints);
  436. }
  437. return sprintf(
  438. '%s/create%s',
  439. $this->resource(),
  440. $queryString ? ('?'.$queryString) : ''
  441. );
  442. }
  443. /**
  444. * @param string $key
  445. *
  446. * @return string
  447. */
  448. public function getEditUrl($key)
  449. {
  450. $url = "{$this->resource()}/{$key}/edit";
  451. $queryString = '';
  452. if ($constraints = $this->model()->getConstraints()) {
  453. $queryString = http_build_query($constraints);
  454. }
  455. return $url.($queryString ? ('?'.$queryString) : '');
  456. }
  457. /**
  458. * @param \Closure $closure
  459. *
  460. * @return Grid\Tools\RowSelector
  461. */
  462. public function rowSelector()
  463. {
  464. return $this->rowSelector ?: ($this->rowSelector = new Grid\Tools\RowSelector($this));
  465. }
  466. /**
  467. * Prepend checkbox column for grid.
  468. *
  469. * @return void
  470. */
  471. protected function prependRowSelectorColumn()
  472. {
  473. if (! $this->options['row_selector']) {
  474. return;
  475. }
  476. $rowSelector = $this->rowSelector();
  477. $keyName = $this->getKeyName();
  478. $this->prependColumn(
  479. Grid\Column::SELECT_COLUMN_NAME
  480. )->setLabel($rowSelector->renderHeader())->display(function () use ($rowSelector, $keyName) {
  481. return $rowSelector->renderColumn($this, $this->{$keyName});
  482. });
  483. }
  484. /**
  485. * @param string $width
  486. * @param string $height
  487. *
  488. * @return $this
  489. */
  490. public function setDialogFormDimensions(string $width, string $height)
  491. {
  492. $this->options['dialog_form_area'] = [$width, $height];
  493. return $this;
  494. }
  495. /**
  496. * Render create button for grid.
  497. *
  498. * @return string
  499. */
  500. public function renderCreateButton()
  501. {
  502. if (! $this->options['create_button']) {
  503. return '';
  504. }
  505. return (new Tools\CreateButton($this))->render();
  506. }
  507. /**
  508. * @param bool $value
  509. *
  510. * @return $this
  511. */
  512. public function withBorder(bool $value = true)
  513. {
  514. $this->options['bordered'] = $value;
  515. return $this;
  516. }
  517. /**
  518. * @param bool $value
  519. *
  520. * @return $this
  521. */
  522. public function tableCollapse(bool $value = true)
  523. {
  524. $this->options['table_collapse'] = $value;
  525. return $this;
  526. }
  527. /**
  528. * 显示横轴滚动条.
  529. *
  530. * @param bool $value
  531. *
  532. * @return $this
  533. */
  534. public function scrollbar(bool $value = true)
  535. {
  536. $this->options['table_scrollbar'] = $value;
  537. return $this;
  538. }
  539. /**
  540. * Set grid header.
  541. *
  542. * @param Closure|string|Renderable $content
  543. *
  544. * @return $this
  545. */
  546. public function header($content)
  547. {
  548. $this->header[] = $content;
  549. return $this;
  550. }
  551. /**
  552. * Render grid header.
  553. *
  554. * @return string
  555. */
  556. public function renderHeader()
  557. {
  558. if (! $this->header) {
  559. return '';
  560. }
  561. return <<<HTML
  562. <div class="card-header clearfix" style="border-bottom: 0;background: transparent;padding: 0">{$this->renderHeaderOrFooter($this->header)}</div>
  563. HTML;
  564. }
  565. protected function renderHeaderOrFooter($callbacks)
  566. {
  567. $target = [$this->processFilter()];
  568. $content = [];
  569. foreach ($callbacks as $callback) {
  570. $content[] = Helper::render($callback, $target);
  571. }
  572. if (empty($content)) {
  573. return '';
  574. }
  575. return implode('<div class="mb-1 clearfix"></div>', $content);
  576. }
  577. /**
  578. * Set grid footer.
  579. *
  580. * @param Closure|string|Renderable $content
  581. *
  582. * @return $this
  583. */
  584. public function footer($content)
  585. {
  586. $this->footer[] = $content;
  587. return $this;
  588. }
  589. /**
  590. * Render grid footer.
  591. *
  592. * @return string
  593. */
  594. public function renderFooter()
  595. {
  596. if (! $this->footer) {
  597. return '';
  598. }
  599. return <<<HTML
  600. <div class="box-footer clearfix">{$this->renderHeaderOrFooter($this->footer)}</div>
  601. HTML;
  602. }
  603. /**
  604. * Get or set option for grid.
  605. *
  606. * @param string|array $key
  607. * @param mixed $value
  608. *
  609. * @return $this|mixed
  610. */
  611. public function option($key, $value = null)
  612. {
  613. if (is_null($value)) {
  614. return $this->options[$key] ?? null;
  615. }
  616. if (is_array($key)) {
  617. $this->options = array_merge($this->options, $key);
  618. } else {
  619. $this->options[$key] = $value;
  620. }
  621. return $this;
  622. }
  623. protected function setUpOptions()
  624. {
  625. if ($this->options['bordered']) {
  626. $this->tableCollapse(false);
  627. }
  628. }
  629. /**
  630. * Disable row selector.
  631. *
  632. * @return $this
  633. */
  634. public function disableRowSelector(bool $disable = true)
  635. {
  636. $this->tools->disableBatchActions($disable);
  637. return $this->option('row_selector', ! $disable);
  638. }
  639. /**
  640. * Show row selector.
  641. *
  642. * @return $this
  643. */
  644. public function showRowSelector(bool $val = true)
  645. {
  646. return $this->disableRowSelector(! $val);
  647. }
  648. /**
  649. * Remove create button on grid.
  650. *
  651. * @return $this
  652. */
  653. public function disableCreateButton(bool $disable = true)
  654. {
  655. return $this->option('create_button', ! $disable);
  656. }
  657. /**
  658. * Show create button.
  659. *
  660. * @return $this
  661. */
  662. public function showCreateButton(bool $val = true)
  663. {
  664. return $this->disableCreateButton(! $val);
  665. }
  666. /**
  667. * If allow creation.
  668. *
  669. * @return bool
  670. */
  671. public function allowCreateButton()
  672. {
  673. return $this->options['create_button'];
  674. }
  675. /**
  676. * @param string $mode
  677. *
  678. * @return $this
  679. */
  680. public function createMode(string $mode)
  681. {
  682. return $this->option('create_mode', $mode);
  683. }
  684. /**
  685. * @return $this
  686. */
  687. public function enableDialogCreate()
  688. {
  689. return $this->createMode(self::CREATE_MODE_DIALOG);
  690. }
  691. /**
  692. * Get or set resource path.
  693. *
  694. * @return string
  695. */
  696. public function resource()
  697. {
  698. return $this->resourcePath;
  699. }
  700. /**
  701. * Create a grid instance.
  702. *
  703. * @param mixed ...$params
  704. *
  705. * @return $this
  706. */
  707. public static function make(...$params)
  708. {
  709. return new static(...$params);
  710. }
  711. /**
  712. * @param Closure $closure
  713. *
  714. * @return $this;
  715. */
  716. public function wrap(\Closure $closure)
  717. {
  718. $this->wrapper = $closure;
  719. return $this;
  720. }
  721. /**
  722. * @return bool
  723. */
  724. public function hasWrapper()
  725. {
  726. return $this->wrapper ? true : false;
  727. }
  728. /**
  729. * Add variables to grid view.
  730. *
  731. * @param array $variables
  732. *
  733. * @return $this
  734. */
  735. public function with(array $variables)
  736. {
  737. $this->variables = $variables;
  738. return $this;
  739. }
  740. /**
  741. * Get all variables will used in grid view.
  742. *
  743. * @return array
  744. */
  745. protected function defaultVariables()
  746. {
  747. return [
  748. 'grid' => $this,
  749. 'tableId' => $this->getTableId(),
  750. ];
  751. }
  752. /**
  753. * Set a view to render.
  754. *
  755. * @param string $view
  756. *
  757. * @return $this
  758. */
  759. public function view($view)
  760. {
  761. $this->view = $view;
  762. return $this;
  763. }
  764. /**
  765. * Set grid title.
  766. *
  767. * @param string $title
  768. *
  769. * @return $this
  770. */
  771. public function title($title)
  772. {
  773. $this->variables['title'] = $title;
  774. return $this;
  775. }
  776. /**
  777. * Set grid description.
  778. *
  779. * @param string $description
  780. *
  781. * @return $this
  782. */
  783. public function description($description)
  784. {
  785. $this->variables['description'] = $description;
  786. return $this;
  787. }
  788. /**
  789. * Set resource path for grid.
  790. *
  791. * @param string $path
  792. *
  793. * @return $this
  794. */
  795. public function setResource($path)
  796. {
  797. $this->resourcePath = admin_url($path);
  798. return $this;
  799. }
  800. /**
  801. * 设置是否显示.
  802. *
  803. * @param bool $value
  804. *
  805. * @return $this
  806. */
  807. public function show(bool $value = true)
  808. {
  809. $this->show = $value;
  810. return $this;
  811. }
  812. /**
  813. * 是否显示横向滚动条.
  814. *
  815. * @param bool $value
  816. *
  817. * @return $this
  818. */
  819. public function scrollbarX(bool $value = true)
  820. {
  821. $this->options['scrollbar_x'] = $value;
  822. return $this;
  823. }
  824. /**
  825. * @return string
  826. */
  827. public function formatTableParentClass()
  828. {
  829. $tableCollaps = $this->option('table_collapse') ? 'table-collapse' : '';
  830. $scrollbarX = $this->option('scrollbar_x') ? 'table-scrollbar-x' : '';
  831. return "table-responsive table-wrapper complex-container table-middle mt-1 {$tableCollaps} {$scrollbarX}";
  832. }
  833. /**
  834. * Get the string contents of the grid view.
  835. *
  836. * @return string
  837. */
  838. public function render()
  839. {
  840. $this->callComposing();
  841. $this->build();
  842. $this->applyFixColumns();
  843. $this->setUpOptions();
  844. return $this->doWrap();
  845. }
  846. /**
  847. * @return string
  848. */
  849. protected function doWrap()
  850. {
  851. if (! $this->show) {
  852. return;
  853. }
  854. $view = view($this->view, $this->variables());
  855. if (! $wrapper = $this->wrapper) {
  856. return $view->render();
  857. }
  858. return Helper::render($wrapper($view));
  859. }
  860. /**
  861. * Add column to grid.
  862. *
  863. * @param string $name
  864. *
  865. * @return Column
  866. */
  867. public function __get($name)
  868. {
  869. return $this->addColumn($name);
  870. }
  871. /**
  872. * Dynamically add columns to the grid view.
  873. *
  874. * @param $method
  875. * @param $arguments
  876. *
  877. * @return Column
  878. */
  879. public function __call($method, $arguments)
  880. {
  881. if (static::hasMacro($method)) {
  882. return $this->macroCall($method, $arguments);
  883. }
  884. return $this->addColumn($method, $arguments[0] ?? null);
  885. }
  886. }