Completed
Push — master ( 032e9a...f4f4f4 )
by Arjay
05:40
created

Builder::editors()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Yajra\DataTables\Html;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\Support\Str;
7
use Collective\Html\HtmlBuilder;
8
use Illuminate\Support\Collection;
9
use Illuminate\Support\HtmlString;
10
use Illuminate\Contracts\View\Factory;
11
use Illuminate\Support\Traits\Macroable;
12
use Illuminate\Contracts\Config\Repository;
13
14
class Builder
15
{
16
    use Macroable;
17
18
    /**
19
     * @var Collection
20
     */
21
    public $collection;
22
23
    /**
24
     * @var Repository
25
     */
26
    public $config;
27
28
    /**
29
     * @var Factory
30
     */
31
    public $view;
32
33
    /**
34
     * @var HtmlBuilder
35
     */
36
    public $html;
37
38
    /**
39
     * @var string|array
40
     */
41
    protected $ajax = '';
42
43
    /**
44
     * @var array
45
     */
46
    protected $tableAttributes = [];
47
48
    /**
49
     * @var string
50
     */
51
    protected $template = '';
52
53
    /**
54
     * @var array
55
     */
56
    protected $attributes = [];
57
58
    /**
59
     * Collection of Editors.
60
     *
61
     * @var null|Editor
62
     */
63
    protected $editors = [];
64
65
    /**
66
     * @param Repository $config
67
     * @param Factory $view
68
     * @param HtmlBuilder $html
69
     */
70
    public function __construct(Repository $config, Factory $view, HtmlBuilder $html)
71
    {
72
        $this->config          = $config;
73
        $this->view            = $view;
74
        $this->html            = $html;
75
        $this->collection      = new Collection;
76
        $this->tableAttributes = $this->config->get('datatables-html.table', []);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->config->get('data...s-html.table', array()) of type * is incompatible with the declared type array of property $tableAttributes.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
77
    }
78
79
    /**
80
     * Generate DataTable javascript.
81
     *
82
     * @param  null $script
83
     * @param  array $attributes
84
     * @return \Illuminate\Support\HtmlString
85
     */
86
    public function scripts($script = null, array $attributes = ['type' => 'text/javascript'])
87
    {
88
        $script     = $script ?: $this->generateScripts();
89
        $attributes = $this->html->attributes($attributes);
90
91
        return new HtmlString("<script{$attributes}>{$script}</script>\n");
92
    }
93
94
    /**
95
     * Get generated raw scripts.
96
     *
97
     * @return \Illuminate\Support\HtmlString
98
     */
99
    public function generateScripts()
100
    {
101
        $parameters = $this->generateJson();
102
103
        return new HtmlString(
104
            sprintf($this->template(), $this->getTableAttribute('id'), $parameters)
105
        );
106
    }
107
108
    /**
109
     * Get generated json configuration.
110
     *
111
     * @return string
112
     */
113
    public function generateJson()
114
    {
115
        $args = array_merge(
116
            $this->attributes, [
117
                'ajax'    => $this->ajax,
118
                'columns' => $this->collection->map(function (Column $column) {
119
                    $column = $column->toArray();
120
                    unset($column['attributes']);
121
122
                    return $column;
123
                })->toArray(),
124
            ]
125
        );
126
127
        return $this->parameterize($args);
128
    }
129
130
    /**
131
     * Generate DataTables js parameters.
132
     *
133
     * @param  array $attributes
134
     * @return string
135
     */
136
    public function parameterize($attributes = [])
137
    {
138
        $parameters = (new Parameters($attributes))->toArray();
139
140
        $values       = [];
141
        $replacements = [];
142
143
        foreach (array_dot($parameters) as $key => $value) {
144
            if ($this->isCallbackFunction($value, $key)) {
145
                $values[] = trim($value);
146
                array_set($parameters, $key, '%' . $key . '%');
147
                $replacements[] = '"%' . $key . '%"';
148
            }
149
        }
150
151
        foreach ($parameters as $key => $value) {
152
            array_set($new, $key, $value);
153
        }
154
155
        $json = json_encode($new);
0 ignored issues
show
Bug introduced by
The variable $new does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
156
157
        $json = str_replace($replacements, $values, $json);
158
159
        return $json;
160
    }
161
162
    /**
163
     * Check if given key & value is a valid callback js function.
164
     *
165
     * @param string $value
166
     * @param string $key
167
     * @return bool
168
     */
169
    protected function isCallbackFunction($value, $key)
170
    {
171
        if (empty($value)) {
172
            return false;
173
        }
174
175
        return Str::startsWith(trim($value),
176
                $this->config->get('datatables-html.callback', ['$', '$.', 'function'])) || Str::contains($key,
177
                'editor');
178
    }
179
180
    /**
181
     * Get javascript template to use.
182
     *
183
     * @return string
184
     */
185
    protected function template()
186
    {
187
        $template = $this->template ?: $this->config->get('datatables-html.script', 'datatables::script');
188
189
        return $this->view->make($template, ['editors' => $this->editors])->render();
190
    }
191
192
    /**
193
     * Retrieves HTML table attribute value.
194
     *
195
     * @param string $attribute
196
     * @return mixed
197
     * @throws \Exception
198
     */
199
    public function getTableAttribute($attribute)
200
    {
201
        if (! array_key_exists($attribute, $this->tableAttributes)) {
202
            throw new \Exception("Table attribute '{$attribute}' does not exist.");
203
        }
204
205
        return $this->tableAttributes[$attribute];
206
    }
207
208
    /**
209
     * Get table computed table attributes.
210
     *
211
     * @return array
212
     */
213
    public function getTableAttributes()
214
    {
215
        return $this->tableAttributes;
216
    }
217
218
    /**
219
     * Sets multiple HTML table attributes at once.
220
     *
221
     * @param array $attributes
222
     * @return $this
223
     */
224
    public function setTableAttributes(array $attributes)
225
    {
226
        foreach ($attributes as $attribute => $value) {
227
            $this->tableAttributes[$attribute] = $value;
228
        }
229
230
        return $this;
231
    }
232
233
    /**
234
     * Sets HTML table "id" attribute.
235
     *
236
     * @param string $id
237
     * @return $this
238
     */
239
    public function setTableId($id)
240
    {
241
        return $this->setTableAttribute('id', $id);
242
    }
243
244
    /**
245
     * Sets HTML table attribute(s).
246
     *
247
     * @param string|array $attribute
248
     * @param mixed $value
249
     * @return $this
250
     */
251
    public function setTableAttribute($attribute, $value = null)
252
    {
253
        if (is_array($attribute)) {
254
            return $this->setTableAttributes($attribute);
255
        }
256
257
        $this->tableAttributes[$attribute] = $value;
258
259
        return $this;
260
    }
261
262
    /**
263
     * Add class names to the "class" attribute of HTML table.
264
     *
265
     * @param string|array $class
266
     * @return $this
267
     */
268
    public function addTableClass($class)
269
    {
270
        $class        = is_array($class) ? implode(' ', $class) : $class;
271
        $currentClass = Arr::get(array_change_key_case($this->tableAttributes), 'class');
272
273
        $classes = preg_split('#\s+#', $currentClass . ' ' . $class, null, PREG_SPLIT_NO_EMPTY);
274
        $class   = implode(' ', array_unique($classes));
275
276
        return $this->setTableAttribute('class', $class);
277
    }
278
279
    /**
280
     * Remove class names from the "class" attribute of HTML table.
281
     *
282
     * @param string|array $class
283
     * @return $this
284
     */
285
    public function removeTableClass($class)
286
    {
287
        $class        = is_array($class) ? implode(' ', $class) : $class;
288
        $currentClass = Arr::get(array_change_key_case($this->tableAttributes), 'class');
289
290
        $classes = array_diff(
291
            preg_split('#\s+#', $currentClass, null, PREG_SPLIT_NO_EMPTY),
292
            preg_split('#\s+#', $class, null, PREG_SPLIT_NO_EMPTY)
293
        );
294
        $class = implode(' ', array_unique($classes));
295
296
        return $this->setTableAttribute('class', $class);
297
    }
298
299
    /**
300
     * Add a column in collection usingsl attributes.
301
     *
302
     * @param  array $attributes
303
     * @return $this
304
     */
305
    public function addColumn(array $attributes)
306
    {
307
        $this->collection->push(new Column($attributes));
308
309
        return $this;
310
    }
311
312
    /**
313
     * Add a Column object at the beginning of collection.
314
     *
315
     * @param \Yajra\DataTables\Html\Column $column
316
     * @return $this
317
     */
318
    public function addBefore(Column $column)
319
    {
320
        $this->collection->prepend($column);
321
322
        return $this;
323
    }
324
325
    /**
326
     * Add a column at the beginning of collection using attributes.
327
     *
328
     * @param  array $attributes
329
     * @return $this
330
     */
331
    public function addColumnBefore(array $attributes)
332
    {
333
        $this->collection->prepend(new Column($attributes));
334
335
        return $this;
336
    }
337
338
    /**
339
     * Add a Column object in collection.
340
     *
341
     * @param \Yajra\DataTables\Html\Column $column
342
     * @return $this
343
     */
344
    public function add(Column $column)
345
    {
346
        $this->collection->push($column);
347
348
        return $this;
349
    }
350
351
    /**
352
     * Set datatables columns from array definition.
353
     *
354
     * @param array $columns
355
     * @return $this
356
     */
357
    public function columns(array $columns)
358
    {
359
        $this->collection = new Collection;
360
361
        foreach ($columns as $key => $value) {
362
            if (! is_a($value, Column::class)) {
363
                if (is_array($value)) {
364
                    $attributes = array_merge(
365
                        [
366
                            'name' => $value['name'] ?? $value['data'] ?? $key,
367
                            'data' => $value['data'] ?? $key,
368
                        ],
369
                        $this->setTitle($key, $value)
370
                    );
371
                } else {
372
                    $attributes = [
373
                        'name'  => $value,
374
                        'data'  => $value,
375
                        'title' => $this->getQualifiedTitle($value),
376
                    ];
377
                }
378
379
                $this->collection->push(new Column($attributes));
380
            } else {
381
                $this->collection->push($value);
382
            }
383
        }
384
385
        return $this;
386
    }
387
388
    /**
389
     * Set title attribute of an array if not set.
390
     *
391
     * @param string $title
392
     * @param array $attributes
393
     * @return array
394
     */
395
    public function setTitle($title, array $attributes)
396
    {
397
        if (! isset($attributes['title'])) {
398
            $attributes['title'] = $this->getQualifiedTitle($title);
399
        }
400
401
        return $attributes;
402
    }
403
404
    /**
405
     * Convert string into a readable title.
406
     *
407
     * @param string $title
408
     * @return string
409
     */
410
    public function getQualifiedTitle($title)
411
    {
412
        return Str::title(str_replace(['.', '_'], ' ', Str::snake($title)));
413
    }
414
415
    /**
416
     * Add a checkbox column.
417
     *
418
     * @param  array $attributes
419
     * @param  bool|int $position true to prepend, false to append or a zero-based index for positioning
420
     * @return $this
421
     */
422
    public function addCheckbox(array $attributes = [], $position = false)
423
    {
424
        $attributes = array_merge([
425
            'defaultContent' => '<input type="checkbox" ' . $this->html->attributes($attributes) . '/>',
426
            'title'          => '<input type="checkbox" ' . $this->html->attributes($attributes + ['id' => 'dataTablesCheckbox']) . '/>',
427
            'data'           => 'checkbox',
428
            'name'           => 'checkbox',
429
            'orderable'      => false,
430
            'searchable'     => false,
431
            'exportable'     => false,
432
            'printable'      => true,
433
            'width'          => '10px',
434
        ], $attributes);
435
        $column = new Column($attributes);
436
437
        if ($position === true) {
438
            $this->collection->prepend($column);
439
        } elseif ($position === false || $position >= $this->collection->count()) {
440
            $this->collection->push($column);
441
        } else {
442
            $this->collection->splice($position, 0, [$column]);
0 ignored issues
show
Bug introduced by
It seems like $position defined by parameter $position on line 422 can also be of type boolean; however, Illuminate\Support\Collection::splice() does only seem to accept integer, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
443
        }
444
445
        return $this;
446
    }
447
448
    /**
449
     * Add a action column.
450
     *
451
     * @param  array $attributes
452
     * @return $this
453
     */
454
    public function addAction(array $attributes = [])
455
    {
456
        $attributes = array_merge([
457
            'defaultContent' => '',
458
            'data'           => 'action',
459
            'name'           => 'action',
460
            'title'          => 'Action',
461
            'render'         => null,
462
            'orderable'      => false,
463
            'searchable'     => false,
464
            'exportable'     => false,
465
            'printable'      => true,
466
            'footer'         => '',
467
        ], $attributes);
468
        $this->collection->push(new Column($attributes));
469
470
        return $this;
471
    }
472
473
    /**
474
     * Add a index column.
475
     *
476
     * @param  array $attributes
477
     * @return $this
478
     */
479
    public function addIndex(array $attributes = [])
480
    {
481
        $indexColumn = $this->config->get('datatables.index_column', 'DT_RowIndex');
482
        $attributes  = array_merge([
483
            'defaultContent' => '',
484
            'data'           => $indexColumn,
485
            'name'           => $indexColumn,
486
            'title'          => '',
487
            'render'         => null,
488
            'orderable'      => false,
489
            'searchable'     => false,
490
            'exportable'     => false,
491
            'printable'      => true,
492
            'footer'         => '',
493
        ], $attributes);
494
        $this->collection->push(new Column($attributes));
495
496
        return $this;
497
    }
498
499
    /**
500
     * Setup ajax parameter for datatables pipeline plugin.
501
     *
502
     * @param  string $url
503
     * @param  string $pages
504
     * @return $this
505
     */
506
    public function pipeline($url, $pages)
507
    {
508
        $this->ajax = "$.fn.dataTable.pipeline({ url: '{$url}', pages: {$pages} })";
509
510
        return $this;
511
    }
512
513
    /**
514
     * Setup "ajax" parameter with POST method.
515
     *
516
     * @param  string|array $attributes
517
     * @return $this
518
     */
519
    public function postAjax($attributes = '')
520
    {
521
        if (! is_array($attributes)) {
522
            $attributes = ['url' => (string) $attributes];
523
        }
524
525
        unset($attributes['method']);
526
        Arr::set($attributes, 'type', 'POST');
527
        Arr::set($attributes, 'headers.X-HTTP-Method-Override', 'GET');
528
529
        return $this->ajax($attributes);
530
    }
531
532
    /**
533
     * Setup ajax parameter.
534
     *
535
     * @param  string|array $attributes
536
     * @return $this
537
     */
538
    public function ajax($attributes = '')
539
    {
540
        $this->ajax = $attributes;
541
542
        return $this;
543
    }
544
545
    /**
546
     * Generate DataTable's table html.
547
     *
548
     * @param array $attributes
549
     * @param bool $drawFooter
550
     * @param bool $drawSearch
551
     * @return \Illuminate\Support\HtmlString
552
     */
553
    public function table(array $attributes = [], $drawFooter = false, $drawSearch = false)
554
    {
555
        $this->setTableAttributes($attributes);
556
557
        $th       = $this->compileTableHeaders();
558
        $htmlAttr = $this->html->attributes($this->tableAttributes);
559
560
        $tableHtml  = '<table ' . $htmlAttr . '>';
561
        $searchHtml = $drawSearch ? '<tr class="search-filter">' . implode('',
562
                $this->compileTableSearchHeaders()) . '</tr>' : '';
563
        $tableHtml .= '<thead><tr>' . implode('', $th) . '</tr>' . $searchHtml . '</thead>';
564
        if ($drawFooter) {
565
            $tf = $this->compileTableFooter();
566
            $tableHtml .= '<tfoot><tr>' . implode('', $tf) . '</tr></tfoot>';
567
        }
568
        $tableHtml .= '</table>';
569
570
        return new HtmlString($tableHtml);
571
    }
572
573
    /**
574
     * Compile table headers and to support responsive extension.
575
     *
576
     * @return array
577
     */
578
    private function compileTableHeaders()
579
    {
580
        $th = [];
581
        foreach ($this->collection->toArray() as $row) {
582
            $thAttr = $this->html->attributes(array_merge(
583
                array_only($row, ['class', 'id', 'width', 'style', 'data-class', 'data-hide']),
584
                $row['attributes']
585
            ));
586
            $th[] = '<th ' . $thAttr . '>' . $row['title'] . '</th>';
587
        }
588
589
        return $th;
590
    }
591
592
    /**
593
     * Compile table search headers.
594
     *
595
     * @return array
596
     */
597
    private function compileTableSearchHeaders()
598
    {
599
        $search = [];
600
        foreach ($this->collection->all() as $key => $row) {
601
            $search[] = $row['searchable'] ? '<th>' . (isset($row->search) ? $row->search : '') . '</th>' : '<th></th>';
602
        }
603
604
        return $search;
605
    }
606
607
    /**
608
     * Compile table footer contents.
609
     *
610
     * @return array
611
     */
612
    private function compileTableFooter()
613
    {
614
        $footer = [];
615
        foreach ($this->collection->all() as $row) {
616
            if (is_array($row->footer)) {
617
                $footerAttr = $this->html->attributes(array_only($row->footer,
618
                    ['class', 'id', 'width', 'style', 'data-class', 'data-hide']));
619
                $title    = isset($row->footer['title']) ? $row->footer['title'] : '';
620
                $footer[] = '<th ' . $footerAttr . '>' . $title . '</th>';
621
            } else {
622
                $footer[] = '<th>' . $row->footer . '</th>';
623
            }
624
        }
625
626
        return $footer;
627
    }
628
629
    /**
630
     * Configure DataTable's parameters.
631
     *
632
     * @param  array $attributes
633
     * @return $this
634
     */
635
    public function parameters(array $attributes = [])
636
    {
637
        $this->attributes = array_merge($this->attributes, $attributes);
638
639
        return $this;
640
    }
641
642
    /**
643
     * Get collection of columns.
644
     *
645
     * @return \Illuminate\Support\Collection
646
     */
647
    public function getColumns()
648
    {
649
        return $this->collection;
650
    }
651
652
    /**
653
     * Remove column by name.
654
     *
655
     * @param array $names
656
     * @return $this
657
     */
658
    public function removeColumn(...$names)
659
    {
660
        foreach ($names as $name) {
661
            $this->collection = $this->collection->filter(function (Column $column) use ($name) {
662
                return $column->name !== $name;
663
            })->flatten();
664
        }
665
666
        return $this;
667
    }
668
669
    /**
670
     * Minify ajax url generated when using get request
671
     * by deleting unnecessary url params.
672
     *
673
     * @param string $url
674
     * @param string $script
675
     * @param array $data
676
     * @param array $ajaxParameters
677
     * @return $this
678
     */
679
    public function minifiedAjax($url = '', $script = null, $data = [], $ajaxParameters = [])
680
    {
681
        $this->ajax = [];
682
        $appendData = $this->makeDataScript($data);
683
684
        $this->ajax['url']  = $url;
685
        $this->ajax['type'] = 'GET';
686
        if (isset($this->attributes['serverSide']) ? $this->attributes['serverSide'] : true) {
687
            $this->ajax['data'] = 'function(data) {
688
            for (var i = 0, len = data.columns.length; i < len; i++) {
689
                if (!data.columns[i].search.value) delete data.columns[i].search;
690
                if (data.columns[i].searchable === true) delete data.columns[i].searchable;
691
                if (data.columns[i].orderable === true) delete data.columns[i].orderable;
692
                if (data.columns[i].data === data.columns[i].name) delete data.columns[i].name;
693
            }
694
            delete data.search.regex;';
695
        } else {
696
            $this->ajax['data'] = 'function(data){';
697
        }
698
699
        if ($appendData) {
700
            $this->ajax['data'] .= $appendData;
701
        }
702
703
        if ($script) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $script of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
704
            $this->ajax['data'] .= $script;
705
        }
706
707
        $this->ajax['data'] .= '}';
708
709
        $this->ajax = array_merge($this->ajax, $ajaxParameters);
710
711
        return $this;
712
    }
713
714
    /**
715
     * Make a data script to be appended on ajax request of dataTables.
716
     *
717
     * @param array $data
718
     * @return string
719
     */
720
    protected function makeDataScript(array $data)
721
    {
722
        $script = '';
723
        foreach ($data as $key => $value) {
724
            $script .= PHP_EOL . "data.{$key} = '{$value}';";
725
        }
726
727
        return $script;
728
    }
729
730
    /**
731
     * Attach multiple editors to builder.
732
     *
733
     * @param mixed ...$editors
734
     * @return $this
735
     */
736
    public function editors(...$editors)
737
    {
738
        foreach ($editors as $editor) {
739
            $this->editor($editor);
740
        }
741
742
        return $this;
743
    }
744
745
    /**
746
     * Integrate with DataTables Editor.
747
     *
748
     * @param array|Editor $fields
749
     * @return $this
750
     */
751
    public function editor($fields)
752
    {
753
        $this->setTemplate($this->config->get('datatables-html.editor', 'datatables::editor'));
754
755
        $editor = $this->newEditor($fields);
756
757
        $this->editors[] = $editor;
758
759
        return $this;
760
    }
761
762
    /**
763
     * Set custom javascript template.
764
     *
765
     * @param string $template
766
     * @return $this
767
     */
768
    public function setTemplate($template)
769
    {
770
        $this->template = $template;
771
772
        return $this;
773
    }
774
775
    /**
776
     * @param array|Editor $fields
777
     * @throws \Exception
778
     */
779
    protected function newEditor($fields)
780
    {
781
        if ($fields instanceof Editor) {
782
            $editor = $fields;
783
        } else {
784
            $editor = new Editor;
785
            $editor->fields($fields);
786
        }
787
788
        if (! $editor->table) {
789
            $editor->table($this->getTableAttribute('id'));
790
        }
791
792
        if (! $editor->ajax) {
793
            $editor->ajax($this->getAjaxUrl());
794
        }
795
796
        return $editor;
797
    }
798
799
    /**
800
     * Get ajax url.
801
     *
802
     * @return array|mixed|string
803
     */
804
    public function getAjaxUrl()
805
    {
806
        if (is_array($this->ajax)) {
807
            return $this->ajax['url'] ?: url()->current();
808
        }
809
810
        return $this->ajax ?: url()->current();
811
    }
812
813
    /**
814
     * Compile DataTable callback value.
815
     *
816
     * @param mixed $callback
817
     * @return mixed|string
818
     */
819
    private function compileCallback($callback)
820
    {
821
        if (is_callable($callback)) {
822
            return value($callback);
823
        } elseif ($this->view->exists($callback)) {
824
            return $this->view->make($callback)->render();
825
        }
826
827
        return $callback;
828
    }
829
}
830