3

I can't figure out why my data is not being passed to View I get the message Undefined variable: project

Can someone help identify where i am going wrong?

when i return $project->name straight from the controller it displays the response, however fails to pass to view.

Here is my controller function:

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));


}

And here is my View:

<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>

2 Answers 2

7

Instead of:

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

Type

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.