From 1e5d2ec72db71a9b6fdffbc4a862c544ca3510e5 Mon Sep 17 00:00:00 2001 From: Caleb Porzio Date: Thu, 13 Feb 2020 20:53:06 -0500 Subject: [PATCH] Fix timestamps --- src/Sushi.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Sushi.php b/src/Sushi.php index fa322ea..a4282dd 100644 --- a/src/Sushi.php +++ b/src/Sushi.php @@ -7,8 +7,6 @@ trait Sushi { - public $timestamps = false; - protected static $sushiConnection; public function getRows() @@ -100,11 +98,19 @@ public function migrate() $table->{$type}($column); } - if ($this->timestamps && ! in_array('updated_at', array_keys($firstRow)) || ! in_array('created_at', array_keys($firstRow))) { + if ($this->usesTimestamps() && (! in_array('updated_at', array_keys($firstRow)) || ! in_array('created_at', array_keys($firstRow)))) { $table->timestamps(); } }); static::insert($rows); } + + public function usesTimestamps() + { + // Override the Laravel default value of $timestamps = true; Unless otherwise set. + return (new \ReflectionClass($this))->getProperty('timestamps')->class === static::class + ? parent::usesTimestamps() + : false; + } }