From b2dffde4ab66dda764ae01db3d957bd149e8a185 Mon Sep 17 00:00:00 2001 From: Fergus McDonald Date: Fri, 21 Feb 2020 12:24:08 -0500 Subject: [PATCH] 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. --- src/Html/Options/HasColumns.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Html/Options/HasColumns.php b/src/Html/Options/HasColumns.php index a1d239d..7739a89 100644 --- a/src/Html/Options/HasColumns.php +++ b/src/Html/Options/HasColumns.php @@ -27,6 +27,15 @@ public function columnDefs(array $value) return $this; } + private function camelRelation($column) + { + + $parts = explode('.', $column); + $columnName = array_pop($parts); + $relation = Str::camel(implode('.', $parts)); + + return $relation . ($relation ? '.' : '') . $columnName; + } /** * Set columns option value. * @@ -43,14 +52,14 @@ public function columns(array $columns) if (is_array($value)) { $attributes = array_merge( [ - 'name' => $value['name'] ?? $value['data'] ?? $key, + 'name' => $value['name'] ?? $this->camelRelation($value['data'] ?? $key), 'data' => $value['data'] ?? $key, ], $this->setTitle($key, $value) ); } else { $attributes = [ - 'name' => $value, + 'name' => $this->camelRelation($value), 'data' => $value, 'title' => $this->getQualifiedTitle($value), ];