gpt4 book ai didi

php - 调用非对象上的成员函数 where() ?拉拉维尔 5.2

转载 作者:行者123 更新时间:2023-11-29 11:43:13 24 4
gpt4 key购买 nike

我正在尝试从 2 个表中检索匹配的值,以便创建用户记录。

我的代码:

$states = ['1','2'];
$cities = DB::table('cities')->get();
$state = $faker->randomElement($states);
$city= $faker->randomElement($cities->where('state_id',$state)->value('id'));

当前响应:

“调用非对象上的成员函数 where()”。

编辑1.翻译成英文以便更好地理解。

最佳答案

它应该类似于以下内容:

$states = ['1','2'];
$state = $faker->randomElement($states);
$cities = DB::table('cities')->where('state_id', $state)->lists('id')->all();
$city = $faker->randomElement($cities);

关于php - 调用非对象上的成员函数 where() ?拉拉维尔 5.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35413936/

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