mal_id = $id; $jikan = new Malclient; try { $this->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"; } $this->url = $this->animeInfo->GetUrl(); $this->image_url = $this->animeInfo->getImageUrl(); $this->title_eng = $this->animeInfo->getTitleEnglish(); $this->title_rom = $this->animeInfo->getTitle(); $this->title_nat = $this->animeInfo->getTitleJapanese(); $this->title_pref = $this->animeInfo->getTitle(); $this->anime_type = $this->animeInfo->getType(); $this->broadcasted = $this->animeInfo->getBroadcast(); $this->episodes = $this->animeInfo->getEpisodes(); $this->is_airing = $this->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'); } protected function getInfo() { return $this->animeInfo; } 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; } }