$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 –