rakibdevs / covid19-laravel-api
Laravel package to connect https://rapidapi.com/api-sports/api/ to get covid-19 statistics data for any location on the globe immediately
Requires
- php: ^7.0|^8.0
- guzzlehttp/guzzle: ^6.3.1|^7.0.1
This package is not auto-updated.
Last update: 2024-11-19 20:08:31 UTC
README
Laravel Covid-19 API (covid19-laravel-api) is a Laravel package to connect Open Covid-19 APIs ( https://rapidapi.com/api-sports/api/covid-193 ) and access free API services easily.
Supported APIs
Installation
Install the package through Composer. On the command line:
composer require rakibdevs/covid19-laravel-api
Configuration
If Laravel > 7, no need to add provider
Add the following to your providers
array in config/app.php
:
'providers' => [ // ... RakibDevs\Covid19\Covid19ServiceProvider::class, ], 'aliases' => [ //... 'Covid19' => RakibDevs\Covid19\Covid19::class, ];
Publish the required package configuration file using the artisan command:
$ php artisan vendor:publish
Edit the config/openCovid19.php
file and modify the api_key
value with your Open Covid19 Map api key.
Get an api key here
return [ 'api_key' => '' ];
Usage
Here you can see some example of just how simple this package is to use.
use RakibDevs\Covid19\Covid19; use RakibDevs\Covid19\Facades\Covid; // Get current Covid19 by city name // 1. The traditional way $wt = new Covid19(); $info = $wt->getCountries('ban'); // 2. The Facade way $info = Covid::getCountries('ban');
Output
{
"get":"countries"
"parameters":{
"search":"ban"
}
"errors":[]
"results":3
"response":[
0:"Albania"
1:"Bangladesh"
2:"Lebanon"
]
}
Available Countries
Get all current statistics for all countries
// By country name or portion of string $info = $wt->getCountries('ban'); // Get all countries $info = $wt->getAllCountries();
Output:
{
"get":"countries"
"parameters":[]
"errors":[]
"results":225
"response":[
0:"Afghanistan"
1:"Albania"
........
]
}
Statistics
This endpoint reflects the current status of the spread of the coronavirus in all countries.
It is possible to filter per country to retrieve its current status.
For the current situation in the world use All
// By country name $info = $wt->getStatistics(); // Get statistics $info = $wt->getAllStatistics();
Output:
{
"get":"statistics"
"parameters":{
"country":"bangladesh"
}
"errors":[]
"results":1
"response":[
0:{
"continent":"Asia"
"country":"Bangladesh"
"population":165545725
"cases":{
"new":"+692"
"active":47562
"critical":NULL
"recovered":466064
"1M_pop":"3149"
"total":521382
}
"deaths":{
"new":"+22"
"1M_pop":"47"
"total":7756
}
"tests":{
"1M_pop":"20202"
"total":3344399
}
"day":"2021-01-10"
"time":"2021-01-10T05:30:06+00:00"
}
]
}
History
This dunction refers to the entire history of statistics for a country.
For global results, use .
// By country name [required] and date $info = $wt->getHistory('bangladesh', '2020-01-01');
Output
{
"get":"history"
"parameters":{
"country":"Bangladesh"
"day":"2020-06-02"
}
"errors":[]
"results":1
"response":[
0:{
"continent":"Asia"
"country":"Bangladesh"
"population":164551275
"cases":{
"new":"+2381"
"active":38265
....
Worldwide Summary
Get Covid-19 worldwide summary till current date.
$info = $wt->getSummary();
Output
{
"cases_new": 777635
"cases_active": 67908362
"cases_critical": 325531
"cases_recovered": 193258167
"cases_total": 270304615
"deaths_new": 14668
"deaths_total": 5805634
"tests_total": 1282221510
"time": "2020-03-25T06:00:07+00:00"
}
License
Laravel Open Covid19 API is licensed under The MIT License (MIT).