[英]Get Last Inserted ID in Laravel 4
I'm new to Laravel.. How to Get a Last inserted Id In Laravel model Form. 我是Laravel的新手。如何在Laravel模型表格中获取最后插入的ID。
When Creating a New Project Auto Display the project code from Database 创建新项目时,自动显示数据库中的项目代码
Last Inserted ID + 1 ; 最后插入的ID + 1;
{{ Form::text('project_code', Input::old('name'), array('class' => 'form-control','disabled')) }}
We'll need to see your code to be sure, but if you're using eloquent, then when you insert it into the database using $model->save()
, then $model->id
should have the inserted id. 我们将需要确定您的代码,但是,如果您使用的是雄辩的话,那么当您使用
$model->save()
将其插入数据库时, $model->id
应该具有插入的ID。
so 所以
$model = new Model();
$model->field = $var;
$model->field = $var;
$model->field = $var;
$model->save();
$insert_id = $model->id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.