Laravel 4-在save()上返回用户ID [英] Laravel 4 - Return user id on save()

查看:67
本文介绍了Laravel 4-在save()上返回用户ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以帮助我.

Im wondering if someone can help me out.

当用户注册时,我需要在数据库中创建一条记录,这需要用户新创建的ID.

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();

所以我需要已保存用户的ID.

So i need the ID of the saved user.

有可能吗?

欢呼

推荐答案

我很确定您可以稍后再调用ID,因为它是由Eloquent填充的:

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;

这篇关于Laravel 4-在save()上返回用户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆