传递 API 数据以查看 Laravel
Passing API data to view Laravel
我不明白为什么我的数据没有传递给 View
我收到消息 Undefined variable: project
有人可以帮助确定我哪里出错了吗?
当我 return $project->name 直接来自控制器时,它会显示响应,但无法传递给视图。
这是我的控制器函数:
public function getApi(){
$client = new Client();
$response = $client->get('https://play.geokey.org.uk/api/projects/77');
$body = $response->getBody()->getContents();
$project = json_decode($body);
return view ('response', compact($project));
}
这是我的观点:
<h1>Welcome</h1>
<table class="table table-bordered">
<tr>
<th>Project Name</th>
<th>Date of Creation</th>
<th>Contribution Total</th>
</tr>
<tr>
<td>{{$project->name}}</td>
</tr>
</table>
而不是:
return view ('response', compact($project));
类型
return view ('response', compact('project'));
return view ('response', compact('project'));
而不是 compact($project)
我不明白为什么我的数据没有传递给 View 我收到消息 Undefined variable: project
有人可以帮助确定我哪里出错了吗?
当我 return $project->name 直接来自控制器时,它会显示响应,但无法传递给视图。
这是我的控制器函数:
public function getApi(){
$client = new Client();
$response = $client->get('https://play.geokey.org.uk/api/projects/77');
$body = $response->getBody()->getContents();
$project = json_decode($body);
return view ('response', compact($project));
}
这是我的观点:
<h1>Welcome</h1>
<table class="table table-bordered">
<tr>
<th>Project Name</th>
<th>Date of Creation</th>
<th>Contribution Total</th>
</tr>
<tr>
<td>{{$project->name}}</td>
</tr>
</table>
而不是:
return view ('response', compact($project));
类型
return view ('response', compact('project'));
return view ('response', compact('project'));
而不是 compact($project)