-2

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.

mafortis
  • 6,750
  • 23
  • 130
  • 288

1 Answers1

1

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>
Option
  • 2,605
  • 2
  • 19
  • 29
  • thanks dude, it's working perfectly. before i accept it, if I have such a code `$data = RajaOngkir::Kota()->all();` do you know how to get `cities` base on selected `province` ? – mafortis Jan 17 '18 at 08:16
  • Without seeing code it'd be hard to answer. I'd suggest making a secondary question with the relevant information. – Option Jan 17 '18 at 08:18
  • oh one more thing i can't ge it by `{{ $info->province_id }}` but with `{{ $info['province_id'] }}` can. – mafortis Jan 17 '18 at 08:18
  • No probs. I'll keep my eye out for it and help where possible. – Option Jan 17 '18 at 08:20
  • i've made second question: https://stackoverflow.com/questions/48296541/getting-city-list-base-on-selected-province-in-laravel – mafortis Jan 17 '18 at 08:24