gpt4 book ai didi

php - 传递 API 数据以查看 Laravel

转载 作者:行者123 更新时间:2023-12-04 21:07:00 25 4
gpt4 key购买 nike

我不知道为什么我的数据没有传递给 View我收到消息 undefined variable :项目

有人可以帮助确定我哪里出错了吗?

当我直接从 Controller 返回 $project->name 时,它​​会显示响应,但无法传递给 View 。

这是我的 Controller 功能:

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>

最佳答案

代替:

返回 View ('response', compact($project));

类型

返回 View ('response', compact('project'));

关于php - 传递 API 数据以查看 Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42699676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com