Test.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. $id = request()->input('id','1492541');
  19. $data[] = DB::select("SELECT * FROM sports WHERE data_id = {$id}");
  20. $data[] = $this->football('/odds/live');
  21. return $this->success($data);
  22. }
  23. function football($api, $params = [])
  24. {
  25. $url = config('services.api_football.host');
  26. $url .= $api;
  27. $url .= "?" . http_build_query($params);
  28. $key = config('services.api_football.key');
  29. $options = [
  30. 'http' => [
  31. 'method' => 'GET',
  32. 'header' => "x-rapidapi-key: {$key}"
  33. ]
  34. ];
  35. $context = stream_context_create($options);
  36. $response = file_get_contents($url, false, $context);
  37. if ($response === FALSE) {
  38. die('Error occurred while fetching data');
  39. }
  40. return json_decode($response, true);
  41. }
  42. }