我是 Laravel 的新手.. 如何在 Laravel 模型表单中获取最后插入的 ID。
创建新项目时自动显示数据库中的项目代码
最后插入的 ID + 1 ;
{{ Form::text('project_code', Input::old('name'), array('class' => 'form-control','disabled')) }}
最佳答案
我们需要查看您的代码才能确定,但如果您使用的是 Eloquent,那么当您使用 $model->save()
将其插入数据库时,然后 $model->id
应该有插入的 id。
所以
$model = new Model();
$model->field = $var;
$model->field = $var;
$model->field = $var;
$model->save();
$insert_id = $model->id;
关于php - 在 Laravel 4 中获取最后插入的 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24656633/