Test.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. use Illuminate\Support\Facades\DB;
  7. class Test extends Controller
  8. {
  9. public function index()
  10. {
  11. // $data = $this->football('/countries',[]);
  12. // $data = $this->football('/leagues',['code'=>'DZ']);
  13. // $data = $this->football('/fixtures', ['date' => '2026-03-05']);
  14. // $data[] = Client::timezone();
  15. // $data[] = $this->football('/fixtures', ['date' => '2026-03-05']);
  16. // $data[] = $this->football('/odds',['fixture'=>'1491915']);
  17. // $data = FixtureService::index();
  18. $data[] = DB::select('SELECT * FROM sports WHERE data_id = 1511975');
  19. $data[] = $this->football('/odds/live');
  20. return $this->success($data);
  21. }
  22. function football($api, $params = [])
  23. {
  24. $url = config('services.api_football.host');
  25. $url .= $api;
  26. $url .= "?" . http_build_query($params);
  27. $key = config('services.api_football.key');
  28. $options = [
  29. 'http' => [
  30. 'method' => 'GET',
  31. 'header' => "x-rapidapi-key: {$key}"
  32. ]
  33. ];
  34. $context = stream_context_create($options);
  35. $response = file_get_contents($url, false, $context);
  36. if ($response === FALSE) {
  37. die('Error occurred while fetching data');
  38. }
  39. return json_decode($response, true);
  40. }
  41. }