I have a function which gets the value from a database and returns. When I echo, the value does exist. But returned value is null;
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;
}
Not sure what's wrong in there. It's a laravel project.
Function that is calling this method
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'));
}
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')); }