Do you really have two return statements in your index() function?
May 14, 2016
7
Level 8
Pulling data from an API in laravel
l am trying to do a simple request using the buzzle packgae manager. However it's not working as l expected.
In my controller l have
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Product;
use App\Http\Requests;
use GuzzleHttp\Client;
use GuzzleHttp\Message\Request;
use GuzzleHttp\Message\Response;
class products extends Controller
{
//
public function index()
{
$client = new Client();
$response = $client->get('https://api.envato.com/v1/discovery/search/search/item?site=themeforest.net&category=wordpress&sort_by=relevance&access_token=TOKEN');
retrun $response;
return view('products/show',compact('response'));
}
}
l am then pulling this response into my views like this
@extends('layout')
@section('title', 'Products')
@section('content')
<div class="panel panel-default">
<div class="panel-heading"><h1>Products</h1></div>
<div class="panel-body">
<div class="row">
@foreach ($response as $product)
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<div class="caption">
<h3>{{ $product->name }}</h3>
</div>
</div>
</div>
@endforeach
</div>
</div>
</div>
</div>
@endsection
However this doesn't seem to work. Any ideas what l am doing wrong guys?
Please or to participate in this conversation.