在非对象上调用成员函数 where()? Laravel 5.2
Call to a member function where() on a non-object ? Laravel 5.2
我正在尝试从 2 个表中检索匹配值,以便创建用户记录。
我的代码:
$states = ['1','2'];
$cities = DB::table('cities')->get();
$state = $faker->randomElement($states);
$city= $faker->randomElement($cities->where('state_id',$state)->value('id'));
当前回复:
"Call to a member function where() on a non-object".
编辑 1. 翻译成英文以便更好地理解。
试试这个
$comuna = $faker->randomElement($comunas->where('region_id',$region[0])->where('region_id',$region[1])->get();
应该是这样的:
$states = ['1','2'];
$state = $faker->randomElement($states);
$cities = DB::table('cities')->where('state_id', $state)->lists('id')->all();
$city = $faker->randomElement($cities);
我正在尝试从 2 个表中检索匹配值,以便创建用户记录。
我的代码:
$states = ['1','2'];
$cities = DB::table('cities')->get();
$state = $faker->randomElement($states);
$city= $faker->randomElement($cities->where('state_id',$state)->value('id'));
当前回复:
"Call to a member function where() on a non-object".
编辑 1. 翻译成英文以便更好地理解。
试试这个
$comuna = $faker->randomElement($comunas->where('region_id',$region[0])->where('region_id',$region[1])->get();
应该是这样的:
$states = ['1','2'];
$state = $faker->randomElement($states);
$cities = DB::table('cities')->where('state_id', $state)->lists('id')->all();
$city = $faker->randomElement($cities);