3

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')) }}                 
Mitch
  • 1,374
  • 5
  • 21
  • 39
Agent47
  • 69
  • 3
  • 13
  • possible duplicate of [Laravel, get last insert id using Eloquent](http://stackoverflow.com/questions/21084833/laravel-get-last-insert-id-using-eloquent) – Jeff Lambert Jul 09 '14 at 14:45

1 Answers1

3

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;
samuraiseoul
  • 2,888
  • 9
  • 45
  • 65