I am using Firebird and having the following error:
SQLSTATE[IM001]: Driver does not support this function: driver does not support lastInsertId()
I dig a bit on Laravel sources, and found this piece:
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
{
$query->getConnection()->insert($sql, $values);
$id = $query->getConnection()->getPdo()->lastInsertId($sequence);
return is_numeric($id) ? (int) $id : $id;
}
I wish to modify the approach to use "INSERT INTO TableName (Field1, Field2) values (Value1, Value2) RETURNING ID" that is the way to get the "last insert id" on Firebird
I dig a little more and found vendor/laravel/framework/src/Illuminate/Query/Processors/PostgresProcessor.php and saw it has a custom implementation for the same function
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
{
$connection = $query->getConnection();
$connection->recordsHaveBeenModified();
$result = $connection->selectFromWriteConnection($sql, $values)[0];
$sequence = $sequence ?: 'id';
$id = is_object($result) ? $result->{$sequence} : $result[$sequence];
return is_numeric($id) ? (int) $id : $id;
}
I could not find documentation and samples on how to write custom Processors, I tried to duplicate the Postgres code on another file, searched for other files that references it and made a mimic for Firebird, but without success, I could not find even how to tell that Firebird has a custom processor.
I will be glad if someone has a better approach to solve the problem, or could point me out the documentation where I can learn how to code and configure a custom processor. I have searched a lot and found nothing
There is no native support for Firebird in Laravel. See supported DB engines
However it seems you can try to use dedicated Firebase driver, for example https://github.com/harrygulliford/laravel-firebird to make it possible to use Firebird database in Laravel