jqh 5 年之前
父節點
當前提交
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)
     public function __construct($name, $label)
     {
     {
         $this->name = $this->formatName($name);
         $this->name = $this->formatName($name);
+        $this->originalName = $name;
 
 
         $this->label = $this->formatLabel($label);
         $this->label = $this->formatLabel($label);
 
 
@@ -195,7 +196,20 @@ class Column
 
 
     protected function formatName($name)
     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;
         return $this->name;
     }
     }
 
 
+    /**
+     * Get orignal name of this column.
+     *
+     * @return mixed
+     */
+    public function getOriginalName()
+    {
+        return $this->originalName;
+    }
+
     /**
     /**
      * @param array|Model $model
      * @param array|Model $model
      */
      */