| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\Controller;
- use App\Services\ApiFootball\Client;
- use App\Services\FixtureService;
- use Illuminate\Support\Facades\DB;
- class Test extends Controller
- {
- public function index()
- {
- // $data = $this->football('/countries',[]);
- // $data = $this->football('/leagues',['code'=>'DZ']);
- // $data = $this->football('/fixtures', ['date' => '2026-03-05']);
- // $data[] = Client::timezone();
- // $data[] = $this->football('/fixtures', ['date' => '2026-03-05']);
- // $data[] = $this->football('/odds',['fixture'=>'1491915']);
- // $data = FixtureService::index();
- $id = request()->input('id','1492541');
- $data[] = DB::select("SELECT * FROM sports WHERE data_id = {$id}");
- $data[] = $this->football('/odds/live');
- 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);
- }
- }
|