Reputation: 79
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')) }}
Upvotes: 3
Views: 3020
Reputation: 2967
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;
Upvotes: 3