简体   繁体   中英

Get Last Inserted ID in Laravel 4

I'm new to Laravel.. How to Get a Last inserted Id In Laravel model Form.

When Creating a New Project Auto Display the project code from Database

Last Inserted 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.

so

$model = new Model();

$model->field = $var;
$model->field = $var;
$model->field = $var;

$model->save();

$insert_id = $model->id;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM