Repository: laravel-shift/blueprint (php)

Issue:
Use `$casts` instead of `$dates` property
### Synopsis:
The Model `$dates` property was deprecated in Laravel 8. In order to keep an eye to the future, Blueprint should register any dates as `$casts` instead - ideally with an inferred date type.

### Proposed Syntax:

```yaml
models:
  Post:
    published_at: datetime nullable
    reviewed_on: date nullable
```

### Expected Behavior:

```php
class Post extends Model
{
    protected $casts = [
        'published_at' => 'datetime',
        'reviewed_on' => 'date',
        // ...
    ];
}
```


Pull request description:
Removes `$dates` property from models on L8+
Closes #391 

Patch:
diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php
index 335bda3..c2994da 100644
--- a/src/Generators/ModelGenerator.php
+++ b/src/Generators/ModelGenerator.php
@@ -141,9 +141,11 @@ class ModelGenerator implements Generator
             $properties .= PHP_EOL.str_replace('[]', $this->pretty_print_array($columns), $this->files->stub('model.casts.stub'));
         }
 
-        $columns = $this->dateColumns($model->columns());
-        if (! empty($columns)) {
-            $properties .= PHP_EOL.str_replace('[]', $this->pretty_print_array($columns, false), $this->files->stub('model.dates.stub'));
+        if (! Blueprint::isLaravel8OrHigher()) {
+            $columns = $this->dateColumns($model->columns());
+            if (! empty($columns)) {
+                $properties .= PHP_EOL.str_replace('[]', $this->pretty_print_array($columns, false), $this->files->stub('model.dates.stub'));
+            }
         }
 
         return trim($properties);
@@ -285,6 +287,20 @@ class ModelGenerator implements Generator
 
     private function castForColumn(Column $column)
     {
+        if (Blueprint::isLaravel8OrHigher()) {
+            if ($column->dataType() === 'date') {
+                return 'date';
+            }
+
+            if (stripos($column->dataType(), 'datetime') !== false) {
+                return 'datetime';
+            }
+
+            if (stripos($column->dataType(), 'timestamp') !== false) {
+                return 'timestamp';
+            }
+        }
+
         if (stripos($column->dataType(), 'integer') || $column->dataType() === 'id') {
             return 'integer';
         }


Test patch:
diff --git a/tests/Feature/Generators/ModelGeneratorTest.php b/tests/Feature/Generators/ModelGeneratorTest.php
index fae6ed3..2d51ff8 100644
--- a/tests/Feature/Generators/ModelGeneratorTest.php
+++ b/tests/Feature/Generators/ModelGeneratorTest.php
@@ -69,12 +69,6 @@ class ModelGeneratorTest extends TestCase
             ->with('model.casts.stub')
             ->andReturn($this->stub('model.casts.stub'));
 
-        if (in_array($definition, ['drafts/readme-example.yaml', 'drafts/all-column-types.yaml'])) {
-            $this->files->expects('stub')
-                ->with('model.dates.stub')
-                ->andReturn($this->stub('model.dates.stub'));
-        }
-
         $this->files->shouldReceive('stub')
             ->with('model.method.stub')
             ->andReturn($this->stub('model.method.stub'));
@@ -214,9 +208,6 @@ class ModelGeneratorTest extends TestCase
             ->with('model.casts.stub')
             ->andReturn($this->stub('model.casts.stub'))
             ->twice();
-        $this->files->expects('stub')
-            ->with('model.dates.stub')
-            ->andReturn(file_get_contents('stubs/model.dates.stub'));
         $this->files->expects('stub')
             ->with('model.method.stub')
             ->andReturn($this->stub('model.method.stub'))
@@ -421,12 +412,6 @@ class ModelGeneratorTest extends TestCase
             ->with('model.casts.stub')
             ->andReturn($this->stub('model.casts.stub'));
 
-        if ($definition === 'drafts/readme-example.yaml') {
-            $this->files->expects('stub')
-                ->with('model.dates.stub')
-                ->andReturn($this->stub('model.dates.stub'));
-        }
-
         $this->files->shouldReceive('stub')
             ->with('model.method.stub')
             ->andReturn($this->stub('model.method.stub'));
diff --git a/tests/fixtures/models/all-column-types-laravel8.php b/tests/fixtures/models/all-column-types-laravel8.php
index 7e935f5..38b2b12 100644
--- a/tests/fixtures/models/all-column-types-laravel8.php
+++ b/tests/fixtures/models/all-column-types-laravel8.php
@@ -75,12 +75,18 @@ class AllType extends Model
     protected $casts = [
         'bigInteger' => 'integer',
         'boolean' => 'boolean',
+        'date' => 'date',
+        'dateTime' => 'datetime',
+        'dateTimeTz' => 'datetime',
         'decimal' => 'decimal',
         'double' => 'double',
         'float' => 'float',
         'json' => 'array',
         'mediumInteger' => 'integer',
+        'nullableTimestamps' => 'timestamp',
         'smallInteger' => 'integer',
+        'timestamp' => 'timestamp',
+        'timestampTz' => 'timestamp',
         'tinyInteger' => 'integer',
         'unsignedBigInteger' => 'integer',
         'unsignedDecimal' => 'decimal',
@@ -90,20 +96,6 @@ class AllType extends Model
         'unsignedTinyInteger' => 'integer',
     ];
 
-    /**
-     * The attributes that should be mutated to dates.
-     *
-     * @var array
-     */
-    protected $dates = [
-        'date',
-        'dateTime',
-        'dateTimeTz',
-        'nullableTimestamps',
-        'timestamp',
-        'timestampTz',
-    ];
-
 
     public function uuid()
     {
diff --git a/tests/fixtures/models/certificate-pascal-case-example-laravel8.php b/tests/fixtures/models/certificate-pascal-case-example-laravel8.php
index e9e4668..2ff5c42 100644
--- a/tests/fixtures/models/certificate-pascal-case-example-laravel8.php
+++ b/tests/fixtures/models/certificate-pascal-case-example-laravel8.php
@@ -31,15 +31,7 @@ class Certificate extends Model
     protected $casts = [
         'id' => 'integer',
         'certificate_type_id' => 'integer',
-    ];
-
-    /**
-     * The attributes that should be mutated to dates.
-     *
-     * @var array
-     */
-    protected $dates = [
-        'expiry_date',
+        'expiry_date' => 'date',
     ];
 
 
diff --git a/tests/fixtures/models/readme-example-laravel8.php b/tests/fixtures/models/readme-example-laravel8.php
index 2bc4e29..dc07e01 100644
--- a/tests/fixtures/models/readme-example-laravel8.php
+++ b/tests/fixtures/models/readme-example-laravel8.php
@@ -28,18 +28,10 @@ class Post extends Model
      */
     protected $casts = [
         'id' => 'integer',
+        'published_at' => 'timestamp',
         'author_id' => 'integer',
     ];
 
-    /**
-     * The attributes that should be mutated to dates.
-     *
-     * @var array
-     */
-    protected $dates = [
-        'published_at',
-    ];
-
 
     public function author()
     {
diff --git a/tests/fixtures/models/readme-example-phpdoc-laravel8.php b/tests/fixtures/models/readme-example-phpdoc-laravel8.php
index 5dc2245..5c524d6 100644
--- a/tests/fixtures/models/readme-example-phpdoc-laravel8.php
+++ b/tests/fixtures/models/readme-example-phpdoc-laravel8.php
@@ -37,18 +37,10 @@ class Post extends Model
      */
     protected $casts = [
         'id' => 'integer',
+        'published_at' => 'timestamp',
         'author_id' => 'integer',
     ];
 
-    /**
-     * The attributes that should be mutated to dates.
-     *
-     * @var array
-     */
-    protected $dates = [
-        'published_at',
-    ];
-
 
     /**
      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo