$country = DB::table('location_countries')->where('name','India')->first();
$country_id = $country['_id'];
echo $country_id;
$states = DB::table('location_states')->where('country_id',$country_id)->first();
echo $states['name'];
上面是我在控制器中运行的代码,我使用jenseggers/mongodb作为mongodb连接。传递到函数时Laravel变量值丢失
直到该部分的代码我可以看到响应当我这样做的回波
$country = DB::table('location_countries')->where('name','India')->first();
$country_id = $country['_id'];
echo $country_id;
我通过$country_id
给函数如下它后显示没有响应
$states = DB::table('location_states')->where('country_id',$country_id)->first();
echo $states['name'];
如果我直接传递字符串像下面的代码,而不是传递$country_id
变量然后我得到一个响应,但如果我传递一个变量没有响应。
$states = DB::table('location_states')->where('country_id','value-here')->first();
为什么会发生这种情况以及如何绕过这种情况。
尝试$ states = DB :: table('location_states') - > where('country_id','=',$ country_id) - > first(); –
之前尝试过,但它没有奏效。 –
尝试dd($ states);就在那条线的下方,看到o/p –