Test.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\ApiFootball\Client;
  5. class Test extends Controller
  6. {
  7. public function index()
  8. {
  9. // $data = $this->football('/countries',[]);
  10. // $data = $this->football('/leagues',['code'=>'DZ']);
  11. // $data = $this->football('/fixtures', ['league' => 186, 'season' => '2024']);
  12. $data =Client::fixtures(['league' => 186, 'season' => '2024']);
  13. return $this->success($data);
  14. }
  15. function football($api, $params = [])
  16. {
  17. $url = config('services.api_football.host');
  18. $url .= $api;
  19. $url .= "?" . http_build_query($params);
  20. $key = config('services.api_football.key');
  21. $options = [
  22. 'http' => [
  23. 'method' => 'GET',
  24. 'header' => "x-rapidapi-key: {$key}"
  25. ]
  26. ];
  27. $context = stream_context_create($options);
  28. $response = file_get_contents($url, false, $context);
  29. if ($response === FALSE) {
  30. die('Error occurred while fetching data');
  31. }
  32. return json_decode($response, true);
  33. }
  34. }