Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
Deprecate the HasUuidPrimaryKey
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Feb 12, 2018
1 parent cf4540a commit ed1a38e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
```

Expand All @@ -58,8 +56,7 @@ use Spatie\BinaryUuid\HasBinaryUuid;

class TestModel extends Model
{
use HasBinaryUuid,
HasUuidPrimaryKey;
use HasBinaryUuid;

public function getKeyName()
{
Expand All @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions src/HasBinaryUuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
17 changes: 3 additions & 14 deletions src/HasUuidPrimaryKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
2 changes: 0 additions & 2 deletions tests/TestModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

0 comments on commit ed1a38e

Please sign in to comment.