扫码关注官方订阅号
已测试,无效
小伙看你根骨奇佳,潜力无限,来学PHP伐。
DB::insertGetId();
如果你使用模型的话,直接返回整个被插入的数据对象;
如果你用的是 save 方法 直接对象->id 就是新增id
$user = User::create(['name' => 'abc']);
$id = $user->id;
User::insertGetId(['name'=>'abc']);
insertGetId要加上table的吧
$id = DB::table('xx')->insertGetId()
楼主save了吗?$user = new User();$user->name = 'xxx';$user->phone = 123456;$user->save();
$user_id = $user->id;
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
DB::insertGetId();
如果你使用模型的话,直接返回整个被插入的数据对象;
如果你用的是 save 方法 直接对象->id 就是新增id
$user = User::create(['name' => 'abc']);
User::insertGetId(['name'=>'abc']);
insertGetId要加上table的吧
$id = DB::table('xx')->insertGetId()
楼主save了吗?
$user = new User();
$user->name = 'xxx';
$user->phone = 123456;
$user->save();
$user_id = $user->id;