diff --git a/CHANGELOG.md b/CHANGELOG.md index 914b6ac..c1b5ade 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to `laravel-binary-uuid` will be documented in this file +## 1.1.5 - 2018-02-12 + +- Better support for route binding #36. +- Deprecate the `HasUuidPrimaryKey` trait, as its functionality is moved to `HasBinaryUuid`. + ## 1.1.4 - 2018-02-08 - Support Laravel 5.6 diff --git a/README.md b/README.md index ead926a..073a87b 100644 --- a/README.md +++ b/README.md @@ -36,17 +36,15 @@ Schema::create('table_name', function (Blueprint $table) { }); ``` -If you want to use uuid as a primary key you must let your model use the `HasBinaryUuid` and the `HasUuidPrimaryKey` traits. +To get your model to work with the encoded UUID, use the `Spatie\BinaryUuid\HasBinaryUuid` trait in your model. ```php use Illuminate\Database\Eloquent\Model; use Spatie\BinaryUuid\HasBinaryUuid; -use Spatie\BinaryUuid\HasUuidPrimaryKey; class TestModel extends Model { - use HasBinaryUuid, - HasUuidPrimaryKey; + use HasBinaryUuid; } ``` @@ -58,8 +56,7 @@ use Spatie\BinaryUuid\HasBinaryUuid; class TestModel extends Model { - use HasBinaryUuid, - HasUuidPrimaryKey; + use HasBinaryUuid; public function getKeyName() { @@ -83,7 +80,6 @@ To make those work, you'll have to change the migration of those notifications t $table->char('id', 36)->primary(); ``` - ### Creating a model The UUID of a model will automatically be generated upon save. diff --git a/src/HasBinaryUuid.php b/src/HasBinaryUuid.php index 86b8446..1cb1743 100644 --- a/src/HasBinaryUuid.php +++ b/src/HasBinaryUuid.php @@ -100,4 +100,19 @@ public function getRouteKeyName() { return 'uuid_text'; } + + public function getKeyName() + { + return 'uuid'; + } + + public function getIncrementing() + { + return false; + } + + public function resolveRouteBinding($value) + { + return $this->withUuid($value)->first(); + } } diff --git a/src/HasUuidPrimaryKey.php b/src/HasUuidPrimaryKey.php index 7309f50..818ac5b 100644 --- a/src/HasUuidPrimaryKey.php +++ b/src/HasUuidPrimaryKey.php @@ -2,20 +2,9 @@ namespace Spatie\BinaryUuid; +/** + * @deprecated The logic of this trait is moved to `Spatie\BinaryUuid\HasBinaryUuid` and this trait will be removed with the next major version. + */ trait HasUuidPrimaryKey { - public function getKeyName() - { - return 'uuid'; - } - - public function getIncrementing() - { - return false; - } - - public function resolveRouteBinding($value) - { - return $this->withUuid($value)->first(); - } } diff --git a/tests/TestModel.php b/tests/TestModel.php index 3ba93a3..0fc4dcb 100644 --- a/tests/TestModel.php +++ b/tests/TestModel.php @@ -4,12 +4,10 @@ use Spatie\BinaryUuid\HasBinaryUuid; use Illuminate\Database\Eloquent\Model; -use Spatie\BinaryUuid\HasUuidPrimaryKey; class TestModel extends Model { use HasBinaryUuid; - use HasUuidPrimaryKey; protected $table = 'test'; }