Agent47
Agent47

Reputation: 79

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')) }}                 

Upvotes: 3

Views: 3020

Answers (1)

samuraiseoul
samuraiseoul

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

Related Questions