本文介绍了Laravel,get last insert id使用Eloquent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用此代码在表中插入数据:

I'm currently using this code to insert data in a table:

public function saveDetailsCompany()
{
    $post = Input::All();

    $data = new Company;

    $data->nombre = $post['name'];
    $data->direccion = $post['address'];
    $data->telefono = $post['phone'];
    $data->email = $post['email'];
    $data->giro = $post['type'];
    $data->fecha_registro = date("Y-m-d H:i:s");
    $data->fecha_modificacion = date("Y-m-d H:i:s");

    if($data->save()) {
        return Response::json(array('success' => true), 200);
    }
}

我想返回最后一个ID,

And I want to return the last ID inserted but I don't know how to get it.

推荐答案

p> 保存后, $ data-> id 应为最后插入的ID。
$ b

After save, $data->id should be the last id inserted.

return Response::json(array('success' => true, 'last_insert_id' => $data->id), 200);

这篇关于Laravel,get last insert id使用Eloquent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 10:10