Laravel guzzel 结果工具 blade laravel
Laravel guzzel result implement to blade laravel
我在 在 laravel blade 中显示 json 数据时遇到问题,我使用 guzzel 请求数据,这是我的代码:
public function index(){
$client = new Client();
$schedules = $client->get('45.112.125.25:5500/md_data/schedules/', [
'query' => [
'vCategory' => '129',
'vStartDate' => '2017-07-01',
'vEndDate' => '2017-09-31',
'vReadKey' => 850601165,
'vRows' => 10,
'vOffset' => 0
]
]);
// return $schedules->getBody();
return view('trainingList')->with('schedules', $schedules->getBody());
}
这个结果:
[{"f_training_schedule_id":324,"f_training_category_id":129,"f_training_category":"Workshop Business","f_city_id":216,"f_city_name":"Kota Jakarta Selatan","f_training_schedule_startdate":"2017-08-11T17:00:00.000Z","f_training_schedule_enddate":"2017-08-12T17:00:00.000Z","f_training_schedule_batch":1,"f_training_schedule_trainer":58,"f_training_schedule_address":"<!--StartFragment-->JL TB Simatupang, Cilandak, RT.3/RW.3, Cilandak Tim., Ps. Minggu<!--EndFragment-->\r\n\r\n<br>"}]
如何从上面的结果中得到具体的数据。
例如我想从 f_training_schedule_id
中获取值
你需要json_decode()
:
return view('trainingList')->with('schedules', json_decode($schedules->getBody(), true));
在您的 blade 模板中
$schedules[0]['f_training_schedule_id'];
前叉:
@foreach ($schedules as $schedule)
<p>{{ $schedule['f_training_schedule_id'] }}</p>
@endforeach
我在 在 laravel blade 中显示 json 数据时遇到问题,我使用 guzzel 请求数据,这是我的代码:
public function index(){
$client = new Client();
$schedules = $client->get('45.112.125.25:5500/md_data/schedules/', [
'query' => [
'vCategory' => '129',
'vStartDate' => '2017-07-01',
'vEndDate' => '2017-09-31',
'vReadKey' => 850601165,
'vRows' => 10,
'vOffset' => 0
]
]);
// return $schedules->getBody();
return view('trainingList')->with('schedules', $schedules->getBody());
}
这个结果:
[{"f_training_schedule_id":324,"f_training_category_id":129,"f_training_category":"Workshop Business","f_city_id":216,"f_city_name":"Kota Jakarta Selatan","f_training_schedule_startdate":"2017-08-11T17:00:00.000Z","f_training_schedule_enddate":"2017-08-12T17:00:00.000Z","f_training_schedule_batch":1,"f_training_schedule_trainer":58,"f_training_schedule_address":"<!--StartFragment-->JL TB Simatupang, Cilandak, RT.3/RW.3, Cilandak Tim., Ps. Minggu<!--EndFragment-->\r\n\r\n<br>"}]
如何从上面的结果中得到具体的数据。
例如我想从 f_training_schedule_id
中获取值你需要json_decode()
:
return view('trainingList')->with('schedules', json_decode($schedules->getBody(), true));
在您的 blade 模板中
$schedules[0]['f_training_schedule_id'];
前叉:
@foreach ($schedules as $schedule)
<p>{{ $schedule['f_training_schedule_id'] }}</p>
@endforeach