samedi 1 avril 2017

Get json via laravel command - Failed to open stream

I am writing a laravel command to read in reddit comments. I am running Laravel Framework version 5.2.45. My handle method looks like the following:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class reddit extends Command
{
    /**...**/
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $str = json_decode(file_get_contents('http://ift.tt/2olu9hs'));
        foreach ($str as $comments) {
            // dd($comments);
            foreach ($comments->data->children as $comment) {
                if ($comment->body_html == 'You') {
                    print_r($comment);
                } else {
                    print_r($comment);
                }
            }
        }
    }
}

When executing the command I get the following error message:

[ErrorException]
file_get_contents(http://ift.tt/2olu9hs): failed to open stream: No such file or directory

Any suggestions what I am doing wrong?

I appreciate your replies!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2nVFLHq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire