PHPackages                             shamithewebdeveloper/laravel-nytimes-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. shamithewebdeveloper/laravel-nytimes-api

ActiveLibrary[API Development](/categories/api)

shamithewebdeveloper/laravel-nytimes-api
========================================

A Laravel package for working with the New York Times API.

v1.0.2(10mo ago)12MITPHPPHP &gt;=7.4

Since Aug 29Pushed 10mo agoCompare

[ Source](https://github.com/ShamiTheWebdeveloper/laravel-nytimes-api)[ Packagist](https://packagist.org/packages/shamithewebdeveloper/laravel-nytimes-api)[ RSS](/packages/shamithewebdeveloper-laravel-nytimes-api/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (2)Versions (2)Used By (0)

Laravel NYTimes API Package
===========================

[](#laravel-nytimes-api-package)

A lightweight Laravel package to easily integrate the New York Times API into your Laravel applications. Fetch the latest news, articles, and top stories directly from NYTimes with simple and elegant syntax.

🚀 Features
----------

[](#-features)

- Simple integration with the New York Times API
- Supports Top Stories, Most Popular, and Article Search endpoints
- Built-in Facade (NYTimes) and helper methods
- Powered by GuzzleHTTP for secure API requests
- Compatible with Laravel 8, 9, 10, 11, and 12

📦 Installation
--------------

[](#-installation)

```
  composer require shamithewebdeveloper/laravel-nytimes-api
```

🔧 Configuration
---------------

[](#-configuration)

1. Publish the config file:

```
  php artisan vendor:publish --tag=nytimes-config
```

2. Add your NYTimes API Key(Public Key) in .env:

`NYTIMES_API_KEY=your_api_key_here`

3. Add this to the service provider:

```
ShamiTheWebdeveloper\NYTimes\NYTimesServiceProvider::class
```

4. If you want to use the NYTimes directly in view files (Optional):

Add this to app/config.php (For Laravel 8,9, and 10)

```
'aliases' => [
        'NYTimes' => \ShamiTheWebdeveloper\NYTimes\Facades\NYTimesFacade::class,
    ]
```

For Laravel 11 or greater, add this to app/Providers/AppServiceProvider.php in register() function

```
use ShamiTheWebdeveloper\NYTimes\Facades\NYTimesFacade;
public function register(): void
    {
        $loader = AliasLoader::getInstance();
        $loader->alias('NYTimes', NYTimesFacade::class);
    }
```

📝 Usage
-------

[](#-usage)

Retrive Data From API

```
use ShamiTheWebdeveloper\NYTimes\NYTimes;

NYTimes::searchArticle('Sports', now()->lastWeekDay, now())->get();
// use get() to get response in array

NYTimes::searchArticle('Sports', now()->lastWeekDay, now())->json();
// use json() to get response in json
```

Get a full response from GuzzleHttp

```
$articlesFullResponse=NYTimes::searchArticle('Sports', '2024-04-01', now())->fullResponse();
dd($articlesFullResponse);
```

Get API Request URL

```
$articleURL=NYTimes::searchArticle('Sports', '2024-04-01', now())->requestURL();
echo $articleURL;
```

For the views

```
@dd(NYTimes::newsSectionList()->get())
```

### Examples

[](#examples)

For Article Search:

```
/*
Parameters
$query (string required), $start_date (string), $end_date (string), $filter_query (string), $sort (string), $page=1 (int)
*/

$articles=NYTimes::searchArticle('Sports', now()->lastWeekDay, now())->get();

foreach ($articles['response']['docs'] as $article)
{
  echo $article['abstract'].'';
  echo $article['web_url'].'';
}
```

For Archive:

```
/*
Parameters
$month (int required), $year (int required)
*/

$archives= NYTimes::archive(5,2025)->get();

foreach ($archives['response']['docs'] as $archive) {
    echo $archive['abstract'].'';
    echo $archive['section_name'].'';
    echo $archive['word_count'].'';
}
```

For Most Popular:

```
/*
Parameters
$type (string required), $period (int), $shareType (string)
*/

$populars= NYTimes::mostPopular('emailed',7)->get();

foreach ($populars['results'] as $popular) {
    echo $popular['section'].'';
    echo $popular['title'].'';
    echo $popular['abstract'].'';
}
```

For Books (Overview)

```
/*
Parameters
$publishedDate (string)
*/

$books=NYTimes::bookOverview('2024-05-04')->get();

echo $books['results']['published_date'].'';
echo 'Books:';

foreach ($books['results']['lists'] as $booklist)
{
  echo $booklist['list_name'].'';

  foreach ($booklist['books'] as $book)
  {
    echo $book['title'].'';
    echo $book['author'].'';
  }
}
```

For Books (List)

```
/*
Parameters
$list (string required) ,$date (string)
*/

$books=NYTimes::bookList('series-books')->get();

echo ''.$books['results']['list_name'].'';

foreach ($books['results']['books'] as $book)
{
    echo $book['title'].'';
    echo $book['author'].'';
}
```

For Times Newswire

```
/*
Parameters
$source (string required) ,$section (string) ,$limit (int), $offset (int)
*/

$news=NYTimes::timesNewswire('nyt','all',30,20)->get();

foreach ($news['results'] as $new)
{
    echo $new['title'].'';
    echo $new['abstract'].'';
    echo $new['url'].'';
}
```

For Times Newswire (Get News By URL)

```
/*
Parameters
$url (string),
*/

$url='https://www.nytimes.com/2025/08/25/arts/dance/kennedy-center-stephen-nakagawa.html';

$news=NYTimes::timesNewswireUrl($url)->get();

foreach ($news['results'] as $new)
{
    echo $new['title'].'';
    echo $new['abstract'].'';
}
```

Get News Sections

```
$sections=NYTimes::newsSectionList()->get();

foreach ($sections['results'] as $section)
{
    echo $section['section'].'';
    echo $section['display_name'].'';
}
```

For Top Stories

```
/*
Parameters
$sections (string),
*/

$stories=NYTimes::topStories('food')->get();

foreach ($stories['results'] as $story)
{
    echo $story['title'].'';
    echo $story['abstract'].'';
    echo $story['url'].'';
}
```

For RSS

```
/*
Parameters
$section (string),
*/

$feeds=NYTimes::rssFeed('Automobiles')->get();

echo $feeds['channel']['title'].'';

foreach ($feeds['channel']['item'] as $feed)
{
    echo $feed['title'].'';
    echo $feed['link'].'';
    echo $feed['description'].'';
}
```

```
// returns data in XML (toXML() Only valid for RSS Feed)
$feeds=NYTimes::rssFeed('Automobiles')->toXML();
header('Content-type: application/xml');
echo $feeds;
```

📌 Requirements
--------------

[](#-requirements)

PHP &gt;= 7.4

Laravel 8, 9, 10, 11 or 12

NYTimes API Key (Free – Get one here ()

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Feel free to open an issue or submit a pull request to improve this package.

📜 License
---------

[](#-license)

This package is open-sourced software licensed under the MIT license.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance54

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

308d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/478505?v=4)[Ehtisham](/maintainers/Ehtisham)[@Ehtisham](https://github.com/Ehtisham)

---

Top Contributors

[![ShamiTheWebdeveloper](https://avatars.githubusercontent.com/u/122912862?v=4)](https://github.com/ShamiTheWebdeveloper "ShamiTheWebdeveloper (14 commits)")

---

Tags

apilaravelpackage newsnytimes

### Embed Badge

![Health badge](/badges/shamithewebdeveloper-laravel-nytimes-api/health.svg)

```
[![Health](https://phpackages.com/badges/shamithewebdeveloper-laravel-nytimes-api/health.svg)](https://phpackages.com/packages/shamithewebdeveloper-laravel-nytimes-api)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)[smodav/mpesa

M-Pesa API implementation

16467.9k1](/packages/smodav-mpesa)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)[files.com/files-php-sdk

Files.com PHP SDK

2481.1k](/packages/filescom-files-php-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
