Repository: laravel-shift/blueprint (php)

Issue:
uuid shorthand generates a relationship in the model 
<!-- PLEASE COMPLETE THIS TEMPLATE -->

- Laravel Version: 8.17.2
- PHP Version: 7.14.3
- Blueprint Version: 1.19.2
- Platform: Mac 

### Issue:

The model generates a uuid relationship see generated code as below 

`<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class AgeCohort extends Model
{
    use HasFactory;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'description',
        'min_age',
        'max_age',
        'uuid',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
    ];


    public function uuid()
    {
        return $this->belongsTo(\App\Models\Uuid::class);
    }
}
`

### draft.yaml:
```yaml
models:
  AgeCohort:
    id
    timestamps
    name: string:100
    description: string:500 nullable
    min_age: integer nullable
    max_age: integer nullable
    uuid: uuid unique
```


Pull request description:
Fix: Invalid UUID relationships
Closes #397 

Patch:
diff --git a/src/Lexers/ModelLexer.php b/src/Lexers/ModelLexer.php
index 8701f73..450e6ac 100644
--- a/src/Lexers/ModelLexer.php
+++ b/src/Lexers/ModelLexer.php
@@ -184,10 +184,10 @@ class ModelLexer implements Lexer
             $model->addColumn($column);
 
             $foreign = collect($column->modifiers())->filter(function ($modifier) {
-                return (is_array($modifier) && key($modifier) === 'foreign') || $modifier === 'foreign';
+                return collect($modifier)->containsStrict('foreign') || collect($modifier)->has('foreign');
             })->flatten()->first();
 
-            if ($column->name() !== 'id' && (in_array($column->dataType(), ['id', 'uuid']) || $foreign)) {
+            if (($column->name() !== 'id') && ($column->dataType() === 'id') || $foreign) {
                 $reference = $column->name();
 
                 if ($foreign && $foreign !== 'foreign') {


Test patch:
diff --git a/tests/Feature/Generators/MigrationGeneratorTest.php b/tests/Feature/Generators/MigrationGeneratorTest.php
index fb7a064..5381e38 100644
--- a/tests/Feature/Generators/MigrationGeneratorTest.php
+++ b/tests/Feature/Generators/MigrationGeneratorTest.php
@@ -795,6 +795,7 @@ class MigrationGeneratorTest extends TestCase
             ['drafts/model-key-constraints.yaml', 'database/migrations/timestamp_create_orders_table.php', 'migrations/model-key-constraints.php'],
             ['drafts/disable-auto-columns.yaml', 'database/migrations/timestamp_create_states_table.php', 'migrations/disable-auto-columns.php'],
             ['drafts/uuid-shorthand.yaml', 'database/migrations/timestamp_create_people_table.php', 'migrations/uuid-shorthand.php'],
+            ['drafts/uuid-shorthand-invalid-relationship.yaml', 'database/migrations/timestamp_create_age_cohorts_table.php', 'migrations/uuid-shorthand-invalid-relationship.php'],
             ['drafts/unconventional-foreign-key.yaml', 'database/migrations/timestamp_create_states_table.php', 'migrations/unconventional-foreign-key.php'],
             ['drafts/resource-statements.yaml', 'database/migrations/timestamp_create_users_table.php', 'migrations/resource-statements.php'],
             ['drafts/enum-options.yaml', 'database/migrations/timestamp_create_messages_table.php', 'migrations/enum-options.php'],
diff --git a/tests/Feature/Generators/ModelGeneratorTest.php b/tests/Feature/Generators/ModelGeneratorTest.php
index 2d51ff8..f1ddd3e 100644
--- a/tests/Feature/Generators/ModelGeneratorTest.php
+++ b/tests/Feature/Generators/ModelGeneratorTest.php
@@ -661,6 +661,7 @@ class ModelGeneratorTest extends TestCase
             ['drafts/resource-statements.yaml', 'app/User.php', 'models/resource-statements.php'],
             ['drafts/all-column-types.yaml', 'app/AllType.php', 'models/all-column-types.php'],
             ['drafts/alias-relationships.yaml', 'app/Salesman.php', 'models/alias-relationships.php'],
+            ['drafts/uuid-shorthand-invalid-relationship.yaml', 'app/AgeCohort.php', 'models/uuid-shorthand-invalid-relationship.php'],
         ];
     }
 
@@ -687,6 +688,7 @@ class ModelGeneratorTest extends TestCase
             ['drafts/resource-statements.yaml', 'app/User.php', 'models/resource-statements-laravel8.php'],
             ['drafts/all-column-types.yaml', 'app/AllType.php', 'models/all-column-types-laravel8.php'],
             ['drafts/alias-relationships.yaml', 'app/Salesman.php', 'models/alias-relationships-laravel8.php'],
+            ['drafts/uuid-shorthand-invalid-relationship.yaml', 'app/AgeCohort.php', 'models/uuid-shorthand-invalid-relationship-laravel8.php'],
         ];
     }
 
diff --git a/tests/fixtures/drafts/uuid-shorthand-invalid-relationship.yaml b/tests/fixtures/drafts/uuid-shorthand-invalid-relationship.yaml
new file mode 100644
index 0000000..5f28ac4
--- /dev/null
+++ b/tests/fixtures/drafts/uuid-shorthand-invalid-relationship.yaml
@@ -0,0 +1,9 @@
+models:
+  AgeCohort:
+    id
+    timestamps
+    name: string:100
+    description: string:500 nullable
+    min_age: integer nullable
+    max_age: integer nullable
+    uuid: uuid unique
\ No newline at end of file
diff --git a/tests/fixtures/migrations/uuid-shorthand-invalid-relationship.php b/tests/fixtures/migrations/uuid-shorthand-invalid-relationship.php
new file mode 100644
index 0000000..a30faf0
--- /dev/null
+++ b/tests/fixtures/migrations/uuid-shorthand-invalid-relationship.php
@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateAgeCohortsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('age_cohorts', function (Blueprint $table) {
+            $table->id();
+            $table->string('name', 100);
+            $table->string('description', 500)->nullable();
+            $table->integer('min_age')->nullable();
+            $table->integer('max_age')->nullable();
+            $table->uuid('uuid')->unique();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('age_cohorts');
+    }
+}
diff --git a/tests/fixtures/models/all-column-types-laravel8.php b/tests/fixtures/models/all-column-types-laravel8.php
index 38b2b12..ae49b55 100644
--- a/tests/fixtures/models/all-column-types-laravel8.php
+++ b/tests/fixtures/models/all-column-types-laravel8.php
@@ -95,10 +95,4 @@ class AllType extends Model
         'unsignedSmallInteger' => 'integer',
         'unsignedTinyInteger' => 'integer',
     ];
-
-
-    public function uuid()
-    {
-        return $this->belongsTo(\App\Uuid::class);
-    }
 }
diff --git a/tests/fixtures/models/all-column-types.php b/tests/fixtures/models/all-column-types.php
index bcefe7c..ce74820 100644
--- a/tests/fixtures/models/all-column-types.php
+++ b/tests/fixtures/models/all-column-types.php
@@ -100,10 +100,4 @@ class AllType extends Model
         'timestamp',
         'timestampTz',
     ];
-
-
-    public function uuid()
-    {
-        return $this->belongsTo(\App\Uuid::class);
-    }
 }
diff --git a/tests/fixtures/models/uuid-shorthand-invalid-relationship-laravel8.php b/tests/fixtures/models/uuid-shorthand-invalid-relationship-laravel8.php
new file mode 100644
index 0000000..ef5639a
--- /dev/null
+++ b/tests/fixtures/models/uuid-shorthand-invalid-relationship-laravel8.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class AgeCohort extends Model
+{
+    use HasFactory;
+
+    /**
+     * The attributes that are mass assignable.
+     *
+     * @var array
+     */
+    protected $fillable = [
+        'name',
+        'description',
+        'min_age',
+        'max_age',
+        'uuid',
+    ];
+
+    /**
+     * The attributes that should be cast to native types.
+     *
+     * @var array
+     */
+    protected $casts = [
+        'id' => 'integer',
+    ];
+}
diff --git a/tests/fixtures/models/uuid-shorthand-invalid-relationship.php b/tests/fixtures/models/uuid-shorthand-invalid-relationship.php
new file mode 100644
index 0000000..998f389
--- /dev/null
+++ b/tests/fixtures/models/uuid-shorthand-invalid-relationship.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class AgeCohort extends Model
+{
+    /**
+     * The attributes that are mass assignable.
+     *
+     * @var array
+     */
+    protected $fillable = [
+        'name',
+        'description',
+        'min_age',
+        'max_age',
+        'uuid',
+    ];
+
+    /**
+     * The attributes that should be cast to native types.
+     *
+     * @var array
+     */
+    protected $casts = [
+        'id' => 'integer',
+    ];
+}