Test.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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('/countries',[]);
  9. // $data = $this->football('/leagues',['code'=>'DZ']);
  10. $data = $this->football('/fixtures', ['league' => 186, 'season' => '2024']);
  11. return $this->success($data);
  12. }
  13. function football($api, $params = [])
  14. {
  15. $url = config('services.api_football.host');
  16. $url .= $api;
  17. $url .= "?" . http_build_query($params);
  18. $key = config('services.api_football.key');
  19. $options = [
  20. 'http' => [
  21. 'method' => 'GET',
  22. 'header' => "x-rapidapi-key: {$key}"
  23. ]
  24. ];
  25. $context = stream_context_create($options);
  26. $response = file_get_contents($url, false, $context);
  27. if ($response === FALSE) {
  28. die('Error occurred while fetching data');
  29. }
  30. return json_decode($response, true);
  31. }
  32. }