gpt4 book ai didi

php - laravel 在插入一行后无法检索 ID

转载 作者:行者123 更新时间:2023-11-29 00:12:47 25 4
gpt4 key购买 nike

这是我的代码

$model = Admin::create(Input::only('username', 'password', 'mobileNumber', 'firstName', 'lastName'));
echo $model->username;
echo $model->ID;
exit;

执行该代码后,我可以在表中看到新行。但我只能看到打印的 username

Admin表已经有一个ID字段,它是主键和自增。

最佳答案

这是因为您使用的是 ID 而不是 id,因为 dd($model)->toArray()) 显示:

array(5) { 
["username"]=> string(7) "asdfasdf"
["firstName"]=> string(5) "tonia"
["lastName"]=> string(8) "asdfasdf"
["mobileNumber"]=> string(11) "56456"
["id"]=> int(4)
}

因此,请确保在每个字段 名称中使用正确的大小写,并且始终尝试在表中使用小写 字段名称。

关于php - laravel 在插入一行后无法检索 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24274261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com