I create new command in laravel:
public function handle()
{
$serversList = [
'cubegame.pl',
'feerko.pl',
'skyup.pl',
'mcosada.pl',
'dragon-craft.pl',
'gc2.pl',
'mc.craftplay.pl',
'iskyblock.pl:25600',
'mc.craftmc.pl',
'mc.realcraft.pl',
'katomc.pl',
'mc.minestar.pl',
];
foreach ($serversList as $server) {
$req = Http::get("https://api.mcsrvstat.us/2/$server");
if ($req->ok()) {
$status = $req->json();
// dump($status['motd']['html'][0]);
$serv = Server::updateOrCreate(
[
'name' => $server,
'ip' => $status['ip']
],
[
'motd' => array_key_exists('motd', $status) ? $status['motd']['html'][0] ?? null : null,
'playersOnline' => array_key_exists('players', $status) ? $status['players']['online'][0] ?? null : null,
'slots' => array_key_exists('players', $status) ? $status['players']['max'][0] ?? null : null,
'version' => $status['version'] ?? null,
'isOnline' => $status['online'],
'icon' => $status['icon'] ?? null,
]
);
}
}
return 0;
}
It adds (or updates), but in database columns ip, motd, playersOnline, slots and version are null for every server. It confused mi because dd($status[‘motd’][‘html’][0]); (and also rest variables) return string or int…
Please help.
Source: Laravel