Reputation: 5509
I'm using Laravel Eloquent for my posts table and using the UUID for my table's primary key. But after saving the model I can't get the ID from it, although all the values are correctly inserted in database.
$post = new App\Post();
$post->uuid = \Webpatser\Uuid\Uuid::generate();
$post->save();
dd($post->uuid); //return null or 0
Adding accessors or using $post->getKey()
could not solve my problem.
Upvotes: 2
Views: 2482
Reputation: 5509
According to Laravel API documentation, Eloquent Models have a boolean property $incrementing
which indicates if the IDs are auto incrementing. To use UUIDs in our models we have to set this variable to false like this:
public $incrementing = false;
Upvotes: 6