diff src/Replacer/TableReplacer.php @ 31:8dd668020310 codex

started converting too bootstrap, also better support for casts
author Luka Sitas <sitas.luka.97@gmail.com>
date Tue, 19 Aug 2025 20:34:53 -0400
parents 827efbf4d73c
children b5c6ebd33547
line wrap: on
line diff
--- a/src/Replacer/TableReplacer.php	Wed Jun 18 09:04:59 2025 -0400
+++ b/src/Replacer/TableReplacer.php	Tue Aug 19 20:34:53 2025 -0400
@@ -44,6 +44,30 @@
     /**
      * Get a string representation of table attributes.
      */
+    protected function getCasts(): string
+    {
+        $insert = '';
+        foreach ($this->get_columns() as $column) {
+            if (in_array($column['name'], $this->columns_to_ignore)) {
+                continue;
+            }
+						$type = $column['type_name'];
+						//date
+						if(in_array($type, ['date'])) {
+							$insert .= sprintf("'%s' => 'date:Y-m-d',", $column['name'])."\n";
+						}
+						//time
+						if(in_array($type, ['timestamp'])) {
+							$insert .= sprintf("'%s' => 'date:Y-m-d H:i',", $column['name'])."\n";
+						}
+        }
+
+        return $insert;
+    }
+
+    /**
+     * Get a string representation of table attributes.
+     */
     protected function getAttributes(): string
     {
         $insert = '';
@@ -112,6 +136,7 @@
         return [
             '// {{ valuesForCreation }}' => $this->getValuesForCreation(),
             '# {{ attributeInsertPoint }}' => $this->getAttributes(),
+            '# {{ castInsertPoint }}' => $this->getCasts(),
             '# {{ fillableInsertPoint }}' => $this->getFillable(),
             '// {{ valuesForValidation }}' => $this->getValuesForValidation(),
         ];