Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查询laravel中的下拉列表?_Laravel_Laravel 4_Laravel 5 - Fatal编程技术网

查询laravel中的下拉列表?

查询laravel中的下拉列表?,laravel,laravel-4,laravel-5,Laravel,Laravel 4,Laravel 5,我在谷歌上搜索过它,但在laravel中找不到下拉列表的查询 请为我提供解决方案,欢迎提供教程和代码示例。谢谢。好了,您应该以这种方式填充它 下面是足够多的Countries课程,让您了解其工作原理: /** * Builds a key/value pair * @param $key * @param $value * @return array|bool */ public static function countryList($key, $value) { $js

我在谷歌上搜索过它,但在laravel中找不到下拉列表的查询


请为我提供解决方案,欢迎提供教程和代码示例。谢谢。

好了,您应该以这种方式填充它

下面是足够多的Countries课程,让您了解其工作原理:

 /**
 * 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
            ]
        },

以下是我使用CustomerModel作为客户详细信息的模型,因为我在下拉列表中获取客户名称:

 $cust_details=CustomerModel::where('active_status',0)->get();
return view('FrontPage.itemadd')->with('cust_details',$cust_details);
在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>

挑选
@foreach($cust\u详细信息为$cust)
{{$cust->customer_name}
@endforeach

你说的“查询下拉列表”是什么意思?是西班牙语。如果你发布一个链接,至少要确保它是可以理解的。他似乎是个拉丁人……我尽了最大的努力……这里只是出于好意……他只需要阅读文章中的代码就可以理解了,所以文本根本不重要。你为什么不从那篇文章中提取代码并改进你的答案呢?如果你明白了,就用它。我现在在工作,我在找东西,我遇到了这个问题,我想我可以给他一个快速的回答。我承认你的想法是对的……我应该给出一个完整的答案,或者根本不回答
 <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>