Php 我想在laravel的“选择选项”菜单中显示整个国家列表
我想在laravel的“选择选项”菜单中显示整个国家列表 这是我的数据: 这是控制器 公共函数getCart() 这是my blade.php *国家Php 我想在laravel的“选择选项”菜单中显示整个国家列表,php,arrays,laravel,Php,Arrays,Laravel,我想在laravel的“选择选项”菜单中显示整个国家列表 这是我的数据: 这是控制器 公共函数getCart() 这是my blade.php *国家 <select class="selectpicker" id="country" name="country"> <option> -- Select One -- </option> @foreach($country->data[0]
<select class="selectpicker" id="country" name="country">
<option> -- Select One -- </option>
@foreach($country->data[0]->name as $countries)
<option> {{$countries}} </option>
@endforeach
</select>
--选择一个--
@foreach($country->data[0]->名称为$countries)
{{$countries}
@endforeach
和错误:
为foreach()提供的参数无效(视图:D:\PPI\projek-1\savanacamp\resources\views\pay viewcart.blade.php)“
--选择一个--
@foreach($country->数据为$item)
{{$item->name}
@endforeach
或
--选择一个--
@foreach($country->数据为$item)
{{$item['name']}
@endforeach
您在foreach
更新您的foreach,如下所示
<select class="selectpicker" id="country" name="country">
<option> -- Select One -- </option>
@foreach($country as $c)
<!-- ^--- supply the list here. -->
<option> {{ $c->data[0]->name }} </option>
<!-- ^--- access the name here -->
@endforeach
</select>
--选择一个--
@foreach(国家为$c)
{{$c->data[0]->name}
@endforeach
我改变了这一点,出现了一个错误“试图获取非对象的属性(视图:D:\PPI\projek-1\savanacamp\resources\views\pay viewcart.blade.php)“更新名称的访问权限,因为我不知道您的模型是什么样子。或者$country
数组/列表的外观。请dd
自己看看。这里我们要回答的主要问题是您对foreach的错误构造。为我们更新您的问题以获得您问题的最新信息,或者查看这些错误并尝试找出您的错误所在。:)我的问题上面列出的数据数组。格式是imageI更改此格式时,出现错误“尝试获取非对象的属性(视图:D:\PPI\projek-1\savanacamp\resources\views\pay viewcart.blade.php)”将{{{$item->name}更改为{$item['name']},如果我尝试此@foreach($country->data as$item)或@foreach($country['data']as$item),则可能需要使用:@foreach($country['data']['data']作为$item)
。错误:“无法将stdClass类型的对象用作数组”
<select class="selectpicker" id="country" name="country">
<option> -- Select One -- </option>
@foreach($country->data as $item)
<option> {{$item->name}} </option>
@endforeach
</select>
<select class="selectpicker" id="country" name="country">
<option> -- Select One -- </option>
@foreach($country->data as $item)
<option> {{$item['name']}} </option>
@endforeach
</select>
<select class="selectpicker" id="country" name="country">
<option> -- Select One -- </option>
@foreach($country as $c)
<!-- ^--- supply the list here. -->
<option> {{ $c->data[0]->name }} </option>
<!-- ^--- access the name here -->
@endforeach
</select>