File tree 2 files changed +39
-1
lines changed
2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -20,12 +20,13 @@ Simply add the "\BinaryCabin\LaravelUUID\Traits\HasUUID;" trait to your model:
20
20
21
21
namespace App;
22
22
23
+ use BinaryCabin\LaravelUUID\Traits\HasUUID;
23
24
use Illuminate\Database\Eloquent\Model;
24
25
25
26
class Project extends Model
26
27
{
27
28
28
- use \BinaryCabin\LaravelUUID\Traits\ HasUUID;
29
+ use HasUUID;
29
30
30
31
}
31
32
```
@@ -47,3 +48,24 @@ And static find method:
47
48
``` php
48
49
\App\Project::findByUUID('uuid')
49
50
```
51
+
52
+ A second trait is available if you use your UUIDs as primary keys:
53
+
54
+ ``` php
55
+ <?php
56
+
57
+ namespace App;
58
+
59
+ use BinaryCabin\LaravelUUID\Traits\HasUUID;
60
+ use BinaryCabin\LaravelUUID\Traits\UUIDIsPrimaryKey;
61
+ use Illuminate\Database\Eloquent\Model;
62
+
63
+ class Project extends Model
64
+ {
65
+
66
+ use HasUUID, UUIDIsPrimaryKey;
67
+
68
+ }
69
+ ```
70
+
71
+ It simply tells Laravel that your primary key isn't an auto-incrementing integer, so it will treat the value correctly.
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace BinaryCabin \LaravelUUID \Traits ;
4
+
5
+ trait UUIDIsPrimaryKey
6
+ {
7
+ public function getIncrementing ()
8
+ {
9
+ return false ;
10
+ }
11
+
12
+ public function getKeyType ()
13
+ {
14
+ return 'string ' ;
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments