| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\Controller;
- class Test extends Controller
- {
- public function index()
- {
- // $data = $this->football('/countries',[]);
- // $data = $this->football('/leagues',['code'=>'DZ']);
- $data = $this->football('/fixtures', ['league' => 186, 'season' => '2024']);
- return $this->success($data);
- }
- function football($api, $params = [])
- {
- $url = config('services.api_football.host');
- $url .= $api;
- $url .= "?" . http_build_query($params);
- $key = config('services.api_football.key');
- $options = [
- 'http' => [
- 'method' => 'GET',
- 'header' => "x-rapidapi-key: {$key}"
- ]
- ];
- $context = stream_context_create($options);
- $response = file_get_contents($url, false, $context);
- if ($response === FALSE) {
- die('Error occurred while fetching data');
- }
- return json_decode($response, true);
- }
- }
|