Files
nhgooi.nl/website/app/Console/Kernel.php
2020-01-18 12:12:15 +01:00

58 lines
1.3 KiB
PHP

<?php
namespace App\Console;
use Illuminate\Support\Facades\Storage;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
private $API_URL;
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$this->API_URL = env('API_URL', 'http://api.6fm.nl/');
// Update latest news (3 items)
$schedule->call(function() {
$latest_news = json_decode(file_get_contents($this->API_URL . 'nieuws/overzicht?pagina=1&aantal=3'));
$news = [];
foreach($latest_news->news as $item_data)
{
$news[] = new \Model\NewsItem($item_data);
}
Storage::disk('local')->put('laatste_nieuws.json', json_encode($news));
})->everyMinute();
// $schedule->command('inspire')
// ->hourly();
}
/**
* Register the Closure based commands for the application.
*
* @return void
*/
protected function commands()
{
require base_path('routes/console.php');
}
}