在laravel中单独从阵列中获取数据
问题描述:
I'm using shipping system where will calculate shipping price.
this is what i get in my blade currently:
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:
what I want is to getting
id
andname
separately so I can use it in input.
答
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>