Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Feed Laravel Package

spatie/laravel-feed

Generate RSS, Atom, and JSON feeds for your Laravel app with minimal code. Install, register Route::feeds(), configure your feed items, and serve standards-compliant feeds from your application quickly and easily.

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package via composer require spatie/laravel-feed, then register feed routes with Route::feeds() in routes/web.php (optionally specifying a URL prefix like 'feeds' for /feeds/rss). Publish the config with php artisan feed:install, which creates config/feed.php—the central place to define feed configurations. Start with a simple example: implement the Feedable interface on a model (e.g., NewsItem) and define toFeedItem() to return a FeedItem instance. Configure the feed in config/feed.php by setting items (e.g., 'App\NewsItem@getFeedItems'), url, title, format (rss/atom/json), and image. Finally, include feed links in your HTML <head> via @include('feed::links') or the <x-feed-links /> Blade component for auto-discovery.

Implementation Patterns

  • Model-based feeds: Implement Feedable on Eloquent models and define toFeedItem(); ensure getFeedItems() is a static method returning a collection/array of models, arrays, or FeedItem instances.
  • Multiple feed types: Define multiple feeds in config/feed.php (e.g., 'news', 'blog') with different URLs, formats, and views—ideal for separating public news, internal updates, or API-based feeds (e.g., /news/rss vs /blog/atom).
  • Custom views per feed: Override the default feed::atom/rss/json view by specifying a view key (e.g., 'view' => 'feeds.news') in the feed config, enabling branding or format tweaks (e.g., adding site logo, custom metadata).
  • Dynamic arguments: Pass route parameters or query constraints to getFeedItems() using config like 'items' => ['App\NewsItem', 'getFeedItems', 'category' => 'tech'].
  • Cached feeds: Cache feed responses using middleware (e.g., Cache::remember('feed', 3600, fn => $items)) or integrate with Laravel’s cache within getFeedItems() for high-traffic sites.
  • Controller-driven feeds: For complex logic, use controller methods instead of model methods: 'items' => ['App\Http\Controllers\NewsController', 'feed'], where the controller method returns an array/collection.

Gotchas and Tips

  • Route order matters: Place Route::feeds() before catch-all routes (e.g., Route::get('/{slug}')) in routes/web.php to avoid 404s; failing to do so is a common cause of silent failures (see changelog v1.0.2).
  • Date handling: Ensure updated in FeedItem uses a \Carbon\Carbon instance or RFC3339-compliant string (e.g., now()->toRfc3339String()); mismatched formats cause validation errors in some feed readers (fixed in v3.1.0+).
  • HTML content: Use summary() for plain text, and description() (if supported by your view) for HTML. Special characters and tags are allowed in summary (v1.0.9+), but avoid raw HTML in title—Spatie auto-wraps titles in CDATA (v1.0.10+).
  • Feed format consistency: The type and contentType keys in config (e.g., 'type' => 'application/rss+xml') are auto-detected, but explicitly set them if serving non-standard MIME types (e.g., JSON feeds).
  • Debugging: Use php artisan route:list | grep feed to verify routes. Inspect raw feed output via curl http://your-app.local/feed to catch XML/JSON validation issues early.
  • Extension point: Override the FeedItem factory behavior by publishing views (php artisan vendor:publish --tag=feed-views) and extending Blade templates. For advanced customization, extend the Feed class or swap views at runtime with Feed::useView().
  • Permissions & cache: When caching feeds, clear cache on model updates (e.g., Feed::clearCache() in model events). Avoid caching dynamic per-user data—feeds should be public.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport