shamithewebdeveloper/laravel-nytimes-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shamithewebdeveloper/laravel-nytimes-api

Composer 安装命令:

composer require shamithewebdeveloper/laravel-nytimes-api

包简介

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

README 文档

README

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

  • 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

  composer require shamithewebdeveloper/laravel-nytimes-api

🔧 Configuration

  1. Publish the config file:
  php artisan vendor:publish --tag=nytimes-config
  1. Add your NYTimes API Key(Public Key) in .env:

NYTIMES_API_KEY=your_api_key_here

  1. Add this to the service provider:
ShamiTheWebdeveloper\NYTimes\NYTimesServiceProvider::class
  1. 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

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

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'].'<br>';
  echo $article['web_url'].'<br>';
}

For Archive:

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

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

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

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'].'<br>';
    echo $popular['title'].'<br>';
    echo $popular['abstract'].'<br>';
}

For Books (Overview)

/*
Parameters
$publishedDate (string)
*/

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

echo $books['results']['published_date'].'<br>';
echo '<h3>Books:</h3>';

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

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

For Books (List)

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

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

echo '<h2>'.$books['results']['list_name'].'</h2>';

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

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'].'<br>';
    echo $new['abstract'].'<br>';
    echo $new['url'].'<br>';
}

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'].'<br>';
    echo $new['abstract'].'<br>';
}

Get News Sections

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

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

For Top Stories

/*
Parameters
$sections (string),
*/

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

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

For RSS

/*
Parameters
$section (string),
*/

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

echo $feeds['channel']['title'].'<br>';

foreach ($feeds['channel']['item'] as $feed)
{
    echo $feed['title'].'<br>';
    echo $feed['link'].'<br>';
    echo $feed['description'].'<br>';
}
// returns data in XML (toXML() Only valid for RSS Feed)
$feeds=NYTimes::rssFeed('Automobiles')->toXML();
header('Content-type: application/xml');
echo $feeds;

📌 Requirements

PHP >= 7.4

Laravel 8, 9, 10, 11 or 12

NYTimes API Key (Free – Get one here (https://developer.nytimes.com)

🤝 Contributing

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

📜 License

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

shamithewebdeveloper/laravel-nytimes-api 适用场景与选型建议

shamithewebdeveloper/laravel-nytimes-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「package」 「api」 「news」 「laravel」 「nytimes」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 shamithewebdeveloper/laravel-nytimes-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 shamithewebdeveloper/laravel-nytimes-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 shamithewebdeveloper/laravel-nytimes-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-29