我有一个函数,它从数据库中获取值并返回。当我回应时,该值确实存在。但返回值为空;函数返回NULL :: laravel
public static function getCountryCode($country) {
$country = (int) $country;
$x = Country::where('id', $country)->get();
$country_code = '';
foreach($x as $row)
$country_code = $row->alpha_2;
//return 'bd';
echo $country_code;
return $country_code;
}
不知道那里有什么问题。这是一个laravel项目。正在调用该方法
public function countryselect()
{
$country_id = HomeController::detectCountry();
$country_code = SiteController::getCountryCode($country_id);
var_dump($country_code);
return View::make('Layout.countryselect', compact('country_id', 'country_code'));
}
你可以显示调用这个方法的代码吗? – bcmcfc 2014-09-20 07:38:11
'public function countryselect() \t { \t \t $ country_id = HomeController :: detectCountry(); \t \t $ country_code = SiteController :: getCountryCode($ country_id); \t \t var_dump($ country_code); \t \t return View:make('Layout.countryselect',compact('country_id','country_code')); \t}' – 2014-09-20 07:42:27
如果将其添加到问题中,格式化会更容易。有一个待处理的编辑,但需要引入。 – bcmcfc 2014-09-20 07:44:42