Skip to content

Commit

Permalink
Fix timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio committed Feb 14, 2020
1 parent e451257 commit 1e5d2ec
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Sushi.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

trait Sushi
{
public $timestamps = false;

protected static $sushiConnection;

public function getRows()
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 1e5d2ec

Please sign in to comment.