jqh 4 tahun lalu
induk
melakukan
404824b907
1 mengubah file dengan 24 tambahan dan 28 penghapusan
  1. 24 28
      src/Grid/Column.php

+ 24 - 28
src/Grid/Column.php

@@ -187,7 +187,6 @@ class Column
     public function __construct($name, $label)
     {
         $this->name = $this->formatName($name);
-        $this->originalName = $name;
 
         $this->label = $this->formatLabel($label);
 
@@ -196,20 +195,7 @@ class Column
 
     protected function formatName($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);
+        return $name;
     }
 
     /**
@@ -366,16 +352,6 @@ class Column
         return $this->name;
     }
 
-    /**
-     * Get orignal name of this column.
-     *
-     * @return mixed
-     */
-    public function getOriginalName()
-    {
-        return $this->originalName;
-    }
-
     /**
      * @param array|Model $model
      */
@@ -543,6 +519,8 @@ class Column
      */
     public function fill(array &$data)
     {
+        $name = $this->getSnakeName($this->name);
+
         $i = 0;
         foreach ($data as $key => &$row) {
             $i++;
@@ -550,7 +528,7 @@ class Column
                 $row['#'] = $i;
             }
 
-            $this->original = $value = Arr::get($row, $this->name);
+            $this->original = $value = Arr::get($row, $name);
 
             $this->value = $value = $this->htmlEntityEncode($value);
 
@@ -558,17 +536,35 @@ class Column
 
             $this->processConditions();
 
-            Arr::set($row, $this->name, $value);
+            Arr::set($row, $name, $value);
 
             if ($this->hasDisplayCallbacks()) {
                 $value = $this->callDisplayCallbacks($this->original);
-                Arr::set($row, $this->name, $value);
+                Arr::set($row, $name, $value);
             }
         }
 
         $this->value = $value ?? null;
     }
 
+    protected function getSnakeName($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);
+    }
+
     /**
      * @return void
      */