Laravel guzzel结果工具到刀片laravel

时间:2017-08-31 15:57:47

标签: laravel blade guzzle

我在在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获取价值

1 个答案:

答案 0 :(得分:0)

您需要json_decode()

return view('trainingList')->with('schedules', json_decode($schedules->getBody(), true));

在您的刀片模板中

$schedules[0]['f_training_schedule_id'];

FOREACH:

@foreach ($schedules as $schedule)
    <p>{{ $schedule['f_training_schedule_id'] }}</p>
@endforeach