2016-02-12 42 views

回答

0
+0

这是西班牙语。如果你发布了一个链接,至少确定它是可以理解的。 – phaberest

+0

他似乎是拉丁文的家伙......我尽力做到最好......只是好心在这里......他只是需要阅读提供的文章中的代码才能理解它,所以文本并不是'完全没有问题 – JAF

+0

为什么不从该文章中提取代码并改进您的答案?如果你了解它,就使用它。 – phaberest

0
{!! Form::select('userCountry', \App\Libraries\Countries::countryList('alpha3', 'country_name') , 'USA' , ['class' => 'form-control']) !!} 

这里的足够的国家类的你要弄清楚它是如何工作:

/** 
* Builds a key/value pair 
* @param $key 
* @param $value 
* @return array|bool 
*/ 
public static function countryList($key, $value) 
{ 
    $json = self::countryData(); 
    $data = json_decode(self::countryData()); 

    if(!$data && !is_array($data)) { 
     return false; 
    } 

    $out = []; 

    foreach($data as $country) { 
     if(property_exists($country, $key) && property_exists($country, $value)) { 
      $out[$country->{$key}] = $country->{$value}; 
     } 
    } 

    return $out; 
} 

public static function countryData() 
{ 
    return str_replace(' ', '', str_replace("\n", '', ' 
    [ 
     { 
      "alpha2": "AF", 
      "alpha3": "AFG", 
      "country_code": "93", 
      "country_name": "Afghanistan", 
      "mobile_begin_with": [ 
       "7" 
      ], 
      "phone_number_lengths": [ 
       9 
      ] 
     }, 
     { 
      "alpha2": "AL", 
      "alpha3": "ALB", 
      "country_code": "355", 
      "country_name": "Albania", 
      "mobile_begin_with": [ 
       "6" 
      ], 
      "phone_number_lengths": [ 
       8 
      ] 
     }, 
     { 
      "alpha2": "DZ", 
      "alpha3": "DZA", 
      "country_code": "213", 
      "country_name": "Algeria", 
      "mobile_begin_with": [ 
       "5", 
       "6", 
       "7" 
      ], 
      "phone_number_lengths": [ 
       9 
      ] 
     }, 
0

这里的我使用CustomerModel作为客户详细信息的模型,我正在获取客户名称作为下拉列表:

$cust_details=CustomerModel::where('active_status',0)->get(); 
return view('FrontPage.itemadd')->with('cust_details',$cust_details); 

in FrontPage.itemadd.blade我使用下面的代码将客户名称放在下拉列表中。

<select id="cab_types" class="form-control" name="customer_name" id="customer_name" required> 
<option value="">Select</option> 
    @foreach($cust_details as $cust) 
    <option value="{{$cust->id}}">{{$cust->customer_name}}</option> 
     @endforeach 
      </select>