Skip to content

Commit f56d767

Browse files
committed
introduce the ability to pass a custom name for a callback column
1 parent b1b86e6 commit f56d767

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/Column.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Mediconesystems\LivewireDatatables;
44

5+
use Closure;
56
use Illuminate\Support\Facades\DB;
67
use Illuminate\Support\Str;
78
use Mediconesystems\LivewireDatatables\Http\Livewire\LivewireDatatable;
@@ -92,11 +93,25 @@ public static function raw($raw)
9293
return $column;
9394
}
9495

95-
public static function callback($columns, $callback, $params = [])
96-
{
96+
/**
97+
* Make a callback function.
98+
*
99+
* @param $columns string The (comma separated) columns that should be retrieved from the database.
100+
* Is being translated directly into the `.sql`.
101+
* @param $callback Closure A callback that defines how the retrieved columns are processed.
102+
* @param $params Array Optional additional parameters that are passed to the given Closure.
103+
* @param $callbackName string Optional string that defines the 'name' of the column.
104+
* Leave empty to let livewire autogenerate a distinct value.
105+
*/
106+
public static function callback(
107+
string $columns,
108+
Closure $callback,
109+
array $params = [],
110+
?string $callbackName = null
111+
) {
97112
$column = new static;
98113

99-
$column->name = 'callback_' . crc32(json_encode(func_get_args()));
114+
$column->name = 'callback_' . ($callbackName ?? crc32(json_encode(func_get_args())));
100115
$column->callback = $callback;
101116
$column->additionalSelects = is_array($columns) ? $columns : array_map('trim', explode(',', $columns));
102117
$column->params = $params;

0 commit comments

Comments
 (0)