Feb 23, 2016
0
Level 1
lastInsertId on non auto incrementing PK
Hi,
I have a table containing a non auto incrementing primary key (it is a string).
I'm not using Eloquent but am using the Illuminate\Database\DatabaseManager to interact with the database through my repositories.
In my FooRepository::create() I have the following:
public function create(array $input)
{
$uuid = Uuid::uuid4()->toString();
$insert = $this->db->table($this->table)->insert($input + ['uuid' => $uuid]);
dd($uuid, $insert, $this->db->table($this->table)->get());
}
When running my tests through sqlite, dd() returns a UUID, however the list of entries doesn't contain the row I have created (even though $insert is true).
I think this is because the insert is being carried out on a different connection, but I need to return the created row within the create() function.
How can I achieve this?
Thanks!
Please or to participate in this conversation.