douqianrou9079 2018-01-17 08:07
浏览 70
已采纳

在laravel中单独从阵列中获取数据

I'm using shipping system where will calculate shipping price.

this is what i get in my blade currently:

screenshot1

As you see I get id of state and then name of state.

here is my function:

public function index() {
        $data = RajaOngkir::Provinsi()->all();
        return view('welcome', compact('data'));
    }

and this is my blade code:

@foreach($data as $sss)
  @foreach($sss as $numbers)
    {{ $numbers }} <br>
  @endforeach
@endforeach

here is {{$data}} dump info:

screenshot2

what I want is to getting id and name separately so I can use it in input.

  • 写回答

1条回答 默认 最新

  • dtdfl62844 2018-01-17 08:12
    关注

    The foreach will loop through anyhow and pull the relevant info. You just then show it within your blade like so:

    @foreach ($data as $info)
        ID: {{ $info->province_id }} <br />
        Name: {{ $info->province }}
    @endforeach
    

    Updated:

    From my re read you want it as a form drop down select so you can calculate shipping fee's therefore you'd simply do:

    <select name="province" id="">
        <option value="">Select</option> -> This will be the default select option
        @foreach ($data as $info)
        <option value="{{ $info->province_id }}">{{ $info->province }}</option>
        @endforeach
    </select>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据