Laravel 4 - Return user id on save()

非 Y 不嫁゛ 提交于 2019-12-10 22:46:31

问题


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


回答1:


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;


来源:https://stackoverflow.com/questions/24226468/laravel-4-return-user-id-on-save

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!