paulund/rss-feed
最新稳定版本:1.0.0
Composer 安装命令:
composer require paulund/rss-feed
包简介
Rss feed package for Laravel
README 文档
README
A Laravel package that will allow you to generate an RSS feed from your website.
Installation
Install the package via composer:
composer require paulund/rss-feed
Usage
To use this package you need to create the controller that will generate the RSS feed.
This controller will then use the classes in this package to generate your RSS feed.
Create Controller
php artisan make:controller RssFeedController
Add Route
Add a route to your web.php file that will point to the controller.
Route::get('rss', 'RssFeedController@index');
Create RSS Feed
In the controller you need to create a new instance of the FeedMeta class that will create your feed meta information.
$feedMeta = new FeedMeta( title: 'RSS Feed Title', description: 'This RSS feed description', link: 'https://www.example.com/rss', pubDate: now()->format(\DateTime::RFC822), lastBuildDate: now()->toDateTimeString(), category: 'General', generator: 'Paulund RSS Feed Generator' );
Then you can create a collection for the feed items you want to add to the feed.
$feedItems = $blogPosts->map(function ($post): array { return [ 'title' => $post->title, 'description' => $post->description, 'link' => route('blog.show', $post->slug), 'pubDate' => (new \DateTime($post->date))->format(\DateTime::RFC822), 'category' => $post->category, ]; });
Then you can create a new instance of the Feed class and pass in the meta and the items.
Using the toResponse method you can return the RSS feed response.
return (new Feed($feedMeta, $feedItems))->toResponse();
Full Controller
<?php namespace App\Http\Controllers; use App\Models\Post; use Illuminate\Http\Request; use Paulund\RssFeed\Feed; use Paulund\RssFeed\FeedMeta; class RssFeedController extends Controller { public function index() { $blogPosts = Post::all(); $feedMeta = new FeedMeta( title: 'RSS Feed Title', description: 'This RSS feed description', link: 'https://www.example.com/rss', pubDate: now()->format(\DateTime::RFC822), lastBuildDate: now()->toDateTimeString(), category: 'General', generator: 'Paulund RSS Feed Generator' ); $feedItems = $blogPosts->map(function ($post): array { return [ 'title' => $post->title, 'description' => $post->description, 'link' => route('blog.show', $post->slug), 'pubDate' => (new \DateTime($post->date))->format(\DateTime::RFC822), 'category' => $post->category, ]; }); return (new Feed($feedMeta, $feedItems))->toResponse(); } }
Now navigate to the /rss route on your website and you should see the RSS feed.
Testing
composer test
paulund/rss-feed 适用场景与选型建议
paulund/rss-feed 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 607 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 10 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「rss」 「content」 「laravel」 「Paulund」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 paulund/rss-feed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 paulund/rss-feed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 paulund/rss-feed 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A block that displays featured content - large image, title, description and link.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
Import an RSS-feed into blog
Portal Options Links
Simple ASCII output of array data
统计信息
- 总下载量: 607
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: Unknown
- 更新时间: 2024-10-21