【发布时间】:2018-01-23 12:35:09
【问题描述】:
我正在尝试将 guzzle 请求中的变量传递给我的视图。
这是我的控制器
$client = new Client();
$res = $client->request('GET', 'https://api.iugu.com/v1/customers?api_token=secret');
$result = $res->getBody();
$clientes = json_decode($result, true);
return view('sections.client.index')->with('clients', $clientes['items']);
但返回错误:
Trying to get property of non-object (View: /var/www/html/cron_verify/resources/views/sections/client/index.blade.php)
这是我的 JSON
这是我的观点
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-12 col-md-3-offset table_box">
<table class="table">
<tr>
<th>Nome</th>
<th>Status</th>
<th>Faturas</th>
<th>Situação</th>
</tr>
@foreach($clients as $value)
<tr>
<td>{{$value->name}}</td>
<td>{{$value->email}}</td>
<td>{{$value->number}}</td>
</tr>
@endforeach
</table>
</div>
</div>
</div>
@endsection
我不明白为什么会收到此错误,因为该值在 JSON 响应中。是什么导致了错误?
【问题讨论】:
-
尝试
dd($clientes)并告诉我们并尝试添加带有查看代码的完整错误消息 -
@Vinicius Rosa 请同时显示您的 html 代码
-
@Sohel0415 我编辑了我的问题。
-
@Kirit 我编辑了我的问题
-
请也显示您的查看代码