Search code examples
laravellaravel-5guzzlegoutte

Goutte Crawler convert JSON


https://api.cinelist.co.uk/get/times/cinema/10565

This link gives me a json list of title and times that the cinema is playing that specific film. I want to get that information and convert it to string however how is that possible? I have used json_decode and it says that node list is empty.

Here's my code:

function odeon(){
    $client = new Client();
    $crawler = $client->request('GET', 'https://api.cinelist.co.uk/get/times/cinema/10565');
    //print $crawler->text()."\n";
    json_decode($crawler);
    print_r($crawler);
}

Solution

  • file_get_contents() does the trick for simple things like these.

    function odeon(){
        $data = file_get_contents('https://api.cinelist.co.uk/get/times/cinema/10565');
    
        $data = json_decode($data);
        return view()->make('odeon')->with(['listings' => $data->listings]);
    
    }
    

    and then in your blade simply do something like this:

    @foreach($listings as $listing)
        <strong>{{$listing->title}} </strong>: 
        @foreach($listing->times as $time)
            <p>{{$time}}</p>
        @endforeach
    @endforeach