Test.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Sport;
  5. use App\Services\ApiFootball\Client;
  6. use App\Services\FixtureService;
  7. use Illuminate\Support\Facades\DB;
  8. class Test extends Controller
  9. {
  10. public function index()
  11. {
  12. FixtureService::index();
  13. $sport = Sport::where('id','>',0)->orderByDesc('id')->first();
  14. $id = $sport->data_id;
  15. $res = FixtureService::odds($id);
  16. return $this->success($res);
  17. }
  18. function football($api, $params = [])
  19. {
  20. $url = config('services.api_football.host');
  21. $url .= $api;
  22. $url .= "?" . http_build_query($params);
  23. $key = config('services.api_football.key');
  24. $options = [
  25. 'http' => [
  26. 'method' => 'GET',
  27. 'header' => "x-rapidapi-key: {$key}"
  28. ]
  29. ];
  30. $context = stream_context_create($options);
  31. $response = file_get_contents($url, false, $context);
  32. if ($response === FALSE) {
  33. die('Error occurred while fetching data');
  34. }
  35. return json_decode($response, true);
  36. }
  37. }