Test.php 1020 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. $res = FixtureService::odds('164327');
  13. return $this->success($res);
  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. }