2016-02-12 85 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>