Test.php 803 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. class Test extends Controller
  5. {
  6. public function index()
  7. {
  8. $data = $this->football();
  9. return $this->success($data);
  10. }
  11. function football()
  12. {
  13. $url = 'https://v3.football.api-sports.io/teams?id=33';
  14. $key = config('services.api_football.key');
  15. $options = [
  16. 'http' => [
  17. 'method' => 'GET',
  18. 'header' => "x-rapidapi-key: {$key}"
  19. ]
  20. ];
  21. $context = stream_context_create($options);
  22. $response = file_get_contents($url, false, $context);
  23. if ($response === FALSE) {
  24. die('Error occurred while fetching data');
  25. }
  26. return json_decode($response, true);
  27. }
  28. }