mal_id = $id; $jikan = new Malclient; try { $animeInfo = $jikan->getAnime( (new \Jikan\Request\Anime\AnimeRequest( $this->mal_id )) ); } catch (\Exception $e) { echo "Problem requesting AnimeInfo for (" . $anime->mal_id . ") continue\n"; echo $e->getMessage(); echo "\n\n"; } if ( strtolower("not yet aired") == strtolower($animeInfo->getStatus()) ) { echo "Anime (" . $this->mal_id . ") has not aired yet. Skipping\n"; return; } $this->url = $animeInfo->GetUrl(); $this->image_url = $animeInfo->getImageUrl(); $this->title_eng = $animeInfo->getTitleEnglish(); $this->title_rom = $animeInfo->getTitle(); $this->title_nat = $animeInfo->getTitleJapanese(); $this->title_pref = $animeInfo->getTitle(); $this->anime_type = $animeInfo->getType(); $this->broadcasted = $animeInfo->getBroadcast(); $this->episodes = $animeInfo->getEpisodes(); $this->is_airing = $animeInfo->isAiring(); } public function getStats() { return $this->hasMany('App\AnimeStats', 'mal_id', 'mal_id'); } public function getAiring() { return $this->hasMany('App\Airing', 'mal_id', 'mal_id'); } public function user() { return $this->belongsToMany('App\MALUser', 'is_watching', 'mal_id', 'user_id') ->as('anime') ->withPivot('episodes_watched', 'score_user') ->withTimestamps(); } public function getDataFromAnilist() { $query = ' query($id: Int!) { Media(idMal: $id, type: ANIME) { title { romaji english native userPreferred } nextAiringEpisode { airingAt timeUntilAiring episode } episodes duration } } '; // Define our query variables and values that will be used in the query request $variables = [ "id" => $this->mal_id, ]; // Make the HTTP Api request try { $http = new \GuzzleHttp\Client; $response = $http->post('https://graphql.anilist.co', [ 'json' => [ 'query' => $query, 'variables' => $variables, ] ]); $data = json_decode( $response->getBody() )->data->Media; } catch (\Exception $e) { echo "Problem with Guzzle connecting to Anilist on anime: (" . $this->mal_id . ")\n"; return ""; } return $data; } }