jqh 5 лет назад
Родитель
Сommit
4a88f94f24
1 измененных файлов с 25 добавлено и 1 удалено
  1. 25 1
      src/Grid/Column.php

+ 25 - 1
src/Grid/Column.php

@@ -187,6 +187,7 @@ class Column
     public function __construct($name, $label)
     {
         $this->name = $this->formatName($name);
+        $this->originalName = $name;
 
         $this->label = $this->formatLabel($label);
 
@@ -195,7 +196,20 @@ class Column
 
     protected function formatName($name)
     {
-        return $name;
+        if (! Str::contains($name, '.')) {
+            return $name;
+        }
+
+        $names = explode('.', $name);
+        $count = count($names);
+
+        foreach ($names as $i => &$name) {
+            if ($i + 1 < $count) {
+                $name = Str::snake($name);
+            }
+        }
+
+        return implode('.', $names);
     }
 
     /**
@@ -352,6 +366,16 @@ class Column
         return $this->name;
     }
 
+    /**
+     * Get orignal name of this column.
+     *
+     * @return mixed
+     */
+    public function getOriginalName()
+    {
+        return $this->originalName;
+    }
+
     /**
      * @param array|Model $model
      */