<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Vinelab\Http\Client as HttpClient;
use App\Requests\SearchRequest;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class SearchResults extends Controller
{
public function index()
{
return view('results.search-results');
}
public function store(Requests\SearchRequest $request)
{
$search_phrase = $request->input('search');
$client = new HttpClient;
$response = $client->get('https://www.reddit.com/search.json?q='. $search_phrase .'');
$responseArray = $response->json();
dd($responseArray);
return view('results.search-results');
}
}
Using the code above, I am making a reddit API call using this HTTP service
https://github.com/Vinelab/http/tree/master
The answer that comes back gives me an array from a lot of data, but I want to get the header field from this and parse it into a Laravel array, which can be sent to a view where I will display the headers in a foreach loop.
I thought it might be possible to save the name of the results in the database, and then query the database and send it through the view. I am new to all of this, so any help and theory would be appreciated.
Is there a way in Laravel 5.2 to convert the output of this JSON array to a useful array that can be compact and sent to a view?