xxxxxxxxxx
<?php
//You could get the latest record by using findBy() with order by, limit and offset parameters
$results = $repository->findBy(array(),array('id'=>'DESC'),1,0);
/*
First argument is for filter criteria
Second argument takes order by criteria
Third argument is for limit
Fourth argument sets offset
Note it will return you the results set as array of objects so you can get single object from result as $results[0]
*/
xxxxxxxxxx
use Doctrine\DBAL\Connection;
// Inject Connection in your service or controller
public function someMethod(Connection $connection)
{
$yourEntity = new YourEntity();
// Set properties of your entity
$connection->insert('your_entity_table', [
// Associative array of data to be inserted
]);
// Get the last insert ID
$lastInsertId = $connection->lastInsertId();
}