Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 雄辩的最后插入_Php_Oop_Orm_Eloquent - Fatal编程技术网

Php 雄辩的最后插入

Php 雄辩的最后插入,php,oop,orm,eloquent,Php,Oop,Orm,Eloquent,我想获得插入到两个表中的“loan_id” 使用return$this->getConnection()->getPdo()->lastInsertId() 我想我至少应该得到最后一个id(该id被指定为“id”并自动递增),但我也没有收到它。(只是空洞的回答) 如果我能得到插入到DB中的完整对象,那就更好了 所以,我想在事务失败时捕获一个异常,并在失败时返回错误消息,在成功时返回$loan_id或保存的对象。怎么做 而不是 $this->getConnection()->getP

我想获得插入到两个表中的“loan_id”

使用
return$this->getConnection()->getPdo()->lastInsertId()
我想我至少应该得到最后一个id(该id被指定为“id”并自动递增),但我也没有收到它。(只是空洞的回答)

如果我能得到插入到DB中的完整对象,那就更好了

所以,我想在事务失败时捕获一个异常,并在失败时返回错误消息,在成功时返回$loan_id或保存的对象。怎么做


而不是

$this->getConnection()->getPdo()->lastInsertId()
您可以这样做:

DB::table('table')->insert([...])->lastInsertId();

并捕获一个异常,请参见:

您有两个插入。您只能从
贷款分期付款
中获取id,因为last_insert()只返回上次执行插入时的一个id。是的,我理解。但是我没有得到任何IDisert->lastInsertId()不起作用。与插入相反,插入成功了:在插入([…])之后,无法流畅地调用insertGetIdboth lastInsertId和insertGetId。