Skip to content

Commit 5171867

Browse files
authored
feat: support UUID data type columns (#66)
1 parent c69a8fb commit 5171867

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ $table->userstamps();
4141
$table->userstampSoftDeletes();
4242
```
4343

44+
Equivalent methods are also available when working with UUIDs.
45+
46+
```php
47+
$table->userstampsUuid();
48+
$table->userstampsUuidSoftDeletes();
49+
```
50+
4451
You can now load the trait within your model, and userstamps will automatically be maintained:
4552

4653
```php

src/UserstampsServiceProvider.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,34 @@ function () {
4242
$this->dropColumn('deleted_by');
4343
}
4444
);
45+
46+
Blueprint::macro(
47+
'userstampsUuid',
48+
function () {
49+
$this->foreignUuid('created_by')->nullable();
50+
$this->foreignUuid('updated_by')->nullable();
51+
}
52+
);
53+
54+
Blueprint::macro(
55+
'userstampsUuidSoftDeletes',
56+
function () {
57+
$this->foreignUuid('deleted_by')->nullable();
58+
}
59+
);
60+
61+
Blueprint::macro(
62+
'dropUserstampsUuid',
63+
function () {
64+
$this->dropColumn('created_by', 'updated_by');
65+
}
66+
);
67+
68+
Blueprint::macro(
69+
'dropUserstampsUuidSoftDeletes',
70+
function () {
71+
$this->dropColumn('deleted_by');
72+
}
73+
);
4574
}
4675
}

tests/UserstampsTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,64 @@ public function test_it_can_drop_userstamps_soft_delete_column()
465465

466466
$this->assertNotContains('deleted_by', $colummns);
467467
}
468+
469+
public function test_it_can_add_userstamps_uuid_columns(): void
470+
{
471+
Schema::create('userstampable', function (Blueprint $table) {
472+
$table->uuid('id')->primary();
473+
$table->userstampsUuid();
474+
});
475+
476+
$colummns = Schema::getColumnListing('userstampable');
477+
478+
$this->assertContains('created_by', $colummns);
479+
$this->assertContains('updated_by', $colummns);
480+
}
481+
482+
public function test_it_can_add_userstamps_uuid_soft_delete_column(): void
483+
{
484+
Schema::create('userstampable', function (Blueprint $table) {
485+
$table->id();
486+
$table->userstampsUuidSoftDeletes();
487+
});
488+
489+
$colummns = Schema::getColumnListing('userstampable');
490+
491+
$this->assertContains('deleted_by', $colummns);
492+
}
493+
494+
public function test_it_can_drop_userstamps_uuid_columns(): void
495+
{
496+
Schema::create('userstampable', function (Blueprint $table) {
497+
$table->id();
498+
$table->userstampsUuid();
499+
});
500+
501+
Schema::table('userstampable', function (Blueprint $table) {
502+
$table->dropUserstampsUuid();
503+
});
504+
505+
$colummns = Schema::getColumnListing('userstampable');
506+
507+
$this->assertNotContains('created_by', $colummns);
508+
$this->assertNotContains('updated_by', $colummns);
509+
}
510+
511+
public function test_it_can_drop_userstamps_uuid_soft_delete_column(): void
512+
{
513+
Schema::create('userstampable', function (Blueprint $table) {
514+
$table->id();
515+
$table->userstampsUuidSoftDeletes();
516+
});
517+
518+
Schema::table('userstampable', function (Blueprint $table) {
519+
$table->dropUserstampsUuidSoftDeletes();
520+
});
521+
522+
$colummns = Schema::getColumnListing('userstampable');
523+
524+
$this->assertNotContains('deleted_by', $colummns);
525+
}
468526
}
469527

470528
class Foo extends Model

0 commit comments

Comments
 (0)