BigJobbies
BigJobbies

Reputation: 193

Laravel 4 - Return user id on save()

Im wondering if someone can help me out.

I need to create a record in my database when a user signs up which needs the users newly created ID.

I have my standard code to insert a user as follows.

$user = new User;
$user->email = Input::get('email');
$user->save();

So i need the ID of the saved user.

Is that possible?

Cheers

Upvotes: 2

Views: 370

Answers (1)

Laurence
Laurence

Reputation: 60048

I'm pretty sure you can just call the ID afterwards as it is populated by Eloquent:

$user = new User;
$user->email = Input::get('email');
$user->save();
echo $user->id;

Upvotes: 4

Related Questions