传递API数据以查看Laravel

Jay*_*692 2 php laravel blade laravel-5

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

有人可以帮助您确定我要去哪里吗?

当我直接从控制器返回$ 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));


}
Run Code Online (Sandbox Code Playgroud)

这是我的观点:

<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>
Run Code Online (Sandbox Code Playgroud)

Bar*_*osz 6

代替:

return view ('response', compact($project));

类型

return view ('response', compact('project'));