Test.php 1.3 KB

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