Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2dffde

Browse files
committed
Modify column option builder to apply camelCase to any relation
component of the name attribute, if the name has not been explicitly specified, as the Laravel convention is for Eloquent relation naming to use camelCase formatting.
1 parent f0abe2f commit b2dffde

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Html/Options/HasColumns.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ public function columnDefs(array $value)
2727
return $this;
2828
}
2929

30+
private function camelRelation($column)
31+
{
32+
33+
$parts = explode('.', $column);
34+
$columnName = array_pop($parts);
35+
$relation = Str::camel(implode('.', $parts));
36+
37+
return $relation . ($relation ? '.' : '') . $columnName;
38+
}
3039
/**
3140
* Set columns option value.
3241
*
@@ -43,14 +52,14 @@ public function columns(array $columns)
4352
if (is_array($value)) {
4453
$attributes = array_merge(
4554
[
46-
'name' => $value['name'] ?? $value['data'] ?? $key,
55+
'name' => $value['name'] ?? $this->camelRelation($value['data'] ?? $key),
4756
'data' => $value['data'] ?? $key,
4857
],
4958
$this->setTitle($key, $value)
5059
);
5160
} else {
5261
$attributes = [
53-
'name' => $value,
62+
'name' => $this->camelRelation($value),
5463
'data' => $value,
5564
'title' => $this->getQualifiedTitle($value),
5665
];

0 commit comments

Comments
 (0)