kirill-latish / laravel-newsapi
Laravel wrapper for https://newsapi.org/
Installs: 1 111
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 3
Open Issues: 0
Type:project
Requires
- php: >=7.0.0
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- laravel/laravel: 5.6
- phpunit/phpunit: ^7.0.2
This package is not auto-updated.
Last update: 2025-02-20 20:16:10 UTC
README
Laravel wrapper for NewsAPI.org API calls. Documentation for the API can be found here
Installation
1- Require the package via Composer in your composer.json
.
{ "require": { "kirill-latish/laravel-newsapi": "^1.0" } }
2- Run Composer to install or update the new requirement.
$ composer install
or
$ composer update
3- Add the service provider to your app/config/app.php
file
NewsAPI\NewsAPIServiceProvider::class,
4- Add the facade to your app/config/app.php
file
'NewsAPI' => NewsAPI\Facades\NewsAPI::class,
5- Publish the configuration file
$ php artisan vendor:publish --provider="NewsAPI\NewsAPIServiceProvider"
6- Review the configuration file and add your key (preferably through env: 'api_key' => env('NEWSAPI_KEY')
)
config/newsapi.php
Usage
Refer to the official docs as to which calls can be made and check the calls in traits under NewsAPI\Requests.
For example, get all sources (if using facade):
use NewsAPI;
...
$response = NewsAPI::sources()->all();
The above returns an object containing a sources
array.
Get a top headlines by country and category:
$response = NewsAPI::topHeadlines()->get([
'country' => 'gb',
'category'=>'sports'
]);
Get all news from bbc.co.uk in English for time period from 2018-05-01 to 2018-05-04 sorted by publication date:
$response = NewsAPI::everything()->get([
'language' => 'en',
'domains'=>'bbc.co.uk',
'from' => '2018-05-01',
'to' => ''2018-05-04,
'sortBy' => 'publishedAt',
]);