{"id":13593232,"url":"https://github.com/spatie/laravel-feed","last_synced_at":"2025-05-13T17:08:57.585Z","repository":{"id":39613643,"uuid":"51826021","full_name":"spatie/laravel-feed","owner":"spatie","description":"Easily generate RSS feeds","archived":false,"fork":false,"pushed_at":"2025-04-22T07:32:14.000Z","size":312,"stargazers_count":936,"open_issues_count":0,"forks_count":104,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-04-23T23:15:35.352Z","etag":null,"topics":["blog","feed","laravel","php","rss"],"latest_commit_sha":null,"homepage":"https://freek.dev/399-a-package-to-easily-generate-feeds-in-laravel","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"spatie","custom":"https://spatie.be/open-source/support-us"}},"created_at":"2016-02-16T10:02:46.000Z","updated_at":"2025-04-22T07:32:18.000Z","dependencies_parsed_at":"2024-11-06T14:38:27.780Z","dependency_job_id":"3af3eebf-8b83-477c-a1f7-24a2ce34a28a","html_url":"https://github.com/spatie/laravel-feed","commit_stats":{"total_commits":348,"total_committers":41,"mean_commits":8.487804878048781,"dds":0.4683908045977011,"last_synced_commit":"19ee055139ec5f5e93676abb8891e8bc36fa7914"},"previous_names":[],"tags_count":64,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-feed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-feed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-feed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-feed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/laravel-feed/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250528900,"owners_count":21445519,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blog","feed","laravel","php","rss"],"created_at":"2024-08-01T16:01:18.184Z","updated_at":"2025-04-23T23:15:41.933Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie","https://spatie.be/open-source/support-us"],"categories":["PHP"],"sub_categories":[],"readme":"\u003cdiv align=\"left\"\u003e\n    \u003ca href=\"https://spatie.be/open-source?utm_source=github\u0026utm_medium=banner\u0026utm_campaign=laravel-feed\"\u003e\n      \u003cpicture\u003e\n        \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://spatie.be/packages/header/laravel-feed/html/dark.webp\"\u003e\n        \u003cimg alt=\"Logo for laravel-feed\" src=\"https://spatie.be/packages/header/laravel-feed/html/light.webp\" height=\"190\"\u003e\n      \u003c/picture\u003e\n    \u003c/a\u003e\n\n\u003ch1\u003eGenerate RSS feeds in a Laravel app\u003c/h1\u003e\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-feed.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-feed)\n[![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![run-tests](https://github.com/spatie/laravel-feed/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-feed/actions/workflows/run-tests.yml)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-feed.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-feed)\n    \n\u003c/div\u003e\n\nThis package provides an easy way to generate a feed for your Laravel application.  Supported formats are [RSS](http://www.whatisrss.com/), [Atom](https://en.wikipedia.org/wiki/Atom_(standard)), and [JSON](https://jsonfeed.org). There's almost no coding required on your part. Just follow the installation instructions, update your config file, and you're good to go.\n\nSpatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-feed.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/laravel-feed)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n``` bash\ncomposer require spatie/laravel-feed\n```\n\nRegister the routes the feeds will be displayed on using the `feeds`-macro.\n\n```php\n// In routes/web.php\nRoute::feeds();\n```\n\nOptionally, you can pass a string as a first argument of the macro. The string will be used as a URL prefix for all configured feeds.\n\nNext, you must publish the config file:\n\n```bash\nphp artisan feed:install\n```\n\nHere's what that looks like:\n\n```php\nreturn [\n    'feeds' =\u003e [\n        'main' =\u003e [\n            /*\n             * Here you can specify which class and method will return\n             * the items that should appear in the feed. For example:\n             * [App\\Model::class, 'getAllFeedItems']\n             *\n             * You can also pass an argument to that method.  Note that their key must be the name of the parameter:             *\n             * [App\\Model::class, 'getAllFeedItems', 'parameterName' =\u003e 'argument']\n             */\n            'items' =\u003e '',\n\n            /*\n             * The feed will be available on this url.\n             */\n            'url' =\u003e '',\n\n            'title' =\u003e 'My feed',\n            'description' =\u003e 'The description of the feed.',\n            'language' =\u003e 'en-US',\n\n            /*\n             * The image to display for the feed.  For Atom feeds, this is displayed as\n             * a banner/logo; for RSS and JSON feeds, it's displayed as an icon.\n             * An empty value omits the image attribute from the feed.\n             */\n            'image' =\u003e '',\n\n            /*\n             * The format of the feed.  Acceptable values are 'rss', 'atom', or 'json'.\n             */\n            'format' =\u003e 'atom',\n\n            /*\n             * The view that will render the feed.\n             */\n            'view' =\u003e 'feed::atom',\n\n            /*\n             * The mime type to be used in the \u003clink\u003e tag.  Set to an empty string to automatically\n             * determine the correct value.\n             */\n            'type' =\u003e '',\n\n            /*\n             * The content type for the feed response.  Set to an empty string to automatically\n             * determine the correct value.\n             */\n            'contentType' =\u003e '',\n        ],\n    ],\n];\n```\n\nOptionally you can publish the view files:\n\n```bash\nphp artisan vendor:publish --provider=\"Spatie\\Feed\\FeedServiceProvider\" --tag=\"feed-views\"\n```\n\n## Usage\n\nImagine you have a model named `NewsItem` that contains records that you want to have displayed in the feed.\n\nFirst you must implement the `Feedable` interface on that model. `Feedable` expects one method: `toFeedItem`, which should return a `FeedItem` instance.\n\n```php\n// app/NewsItem.php\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Spatie\\Feed\\Feedable;\nuse Spatie\\Feed\\FeedItem;\n\nclass NewsItem extends Model implements Feedable\n{\n    public function toFeedItem(): FeedItem\n    {\n        return FeedItem::create()\n            -\u003eid($this-\u003eid)\n            -\u003etitle($this-\u003etitle)\n            -\u003esummary($this-\u003esummary)\n            -\u003eupdated($this-\u003eupdated_at)\n            -\u003elink($this-\u003elink)\n            -\u003eauthorName($this-\u003eauthor)\n            -\u003eauthorEmail($this-\u003eauthorEmail);\n    }\n}\n```\n\nIf you prefer, returning an associative array with the necessary keys will do the trick too.\n\n```php\n// app/NewsItem.php\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Spatie\\Feed\\Feedable;\nuse Spatie\\Feed\\FeedItem;\n\nclass NewsItem extends Model implements Feedable\n{\n    public function toFeedItem(): FeedItem\n    {\n        return FeedItem::create([\n            'id' =\u003e $this-\u003eid,\n            'title' =\u003e $this-\u003etitle,\n            'summary' =\u003e $this-\u003esummary,\n            'updated' =\u003e $this-\u003eupdated_at,\n            'link' =\u003e $this-\u003elink,\n            'authorName' =\u003e $this-\u003eauthorName,\n        ]);\n    }\n}\n```\n\nNext, you'll have to create a method that will return all the items that must be displayed in \nthe feed. You can name that method anything you like and you can do any query you want.\n\n```php\n// app/NewsItem.php\n\npublic static function getFeedItems()\n{\n   return NewsItem::all();\n}\n```\n\nFinally, you have to put the name of your class and the url where you want the feed to rendered\nin the config file:\n\n```php\n// config/feed.php\n\nreturn [\n\n    'feeds' =\u003e [\n        'news' =\u003e [\n            /*\n             * Here you can specify which class and method will return\n             * the items that should appear in the feed. For example:\n             * 'App\\Model@getAllFeedItems'\n             * or\n             * ['App\\Model', 'getAllFeedItems']\n             *\n             * You can also pass an argument to that method.  Note that their key must be the name of the parameter:             * \n             * ['App\\Model@getAllFeedItems', 'parameterName' =\u003e 'argument']\n             * or\n             * ['App\\Model', 'getAllFeedItems', 'parameterName' =\u003e 'argument']\n             */\n            'items' =\u003e 'App\\NewsItem@getFeedItems',\n\n            /*\n             * The feed will be available on this url.\n             */\n            'url' =\u003e '/feed',\n\n            'title' =\u003e 'All newsitems on mysite.com',\n\n            /*\n             * The format of the feed.  Acceptable values are 'rss', 'atom', or 'json'.\n             */\n            'format' =\u003e 'atom',\n\n            /*\n             * Custom view for the items.\n             *\n             * Defaults to feed::feed if not present.\n             */\n            'view' =\u003e 'feed::feed',\n        ],\n    ],\n\n];\n```\n\nThe `items` key must point to a method that returns one of the following:\n\n- An array or collection of `Feedable`s\n- An array or collection of `FeedItem`s\n- An array or collection of arrays containing feed item values\n\n### Customizing your feed views\n\nThis package provides, out of the box, the `feed::feed` view that displays your feeds details.\n\nHowever, you could use a custom view per feed by providing a `view` key inside of your feed configuration.\n\nIn the following example, we're using the previous `News` feed with a custom `feeds.news` view (located on `resources/views/feeds/news.blade.php`):\n\n```php\n// config/feed.php\n\nreturn [\n\n    'feeds' =\u003e [\n        'news' =\u003e [\n            'items' =\u003e ['App\\NewsItem', 'getFeedItems'],\n\n            'url' =\u003e '/feed',\n\n            'title' =\u003e 'All newsitems on mysite.com',\n\n            /*\n             * The format of the feed.  Acceptable values are 'rss', 'atom', or 'json'.\n             */\n            'format' =\u003e 'atom',\n            \n            /*\n             * Custom view for the items.\n             *\n             * Defaults to feed::feed if not present.\n             */\n            'view' =\u003e 'feeds.news',\n        ],\n    ],\n\n];\n```\n\n### Automatically generate feed links\n\nTo discover a feed, feed readers are looking for a tag in the head section of your html documents that looks like this: \n\n```html\n\u003clink rel=\"alternate\" type=\"application/atom+xml\" title=\"News\" href=\"/feed\"\u003e\n```\n\nYou can add this to your `\u003chead\u003e` through a partial view.\n \n```php\n @include('feed::links')\n```\n\nAs an alternative you can use this blade component:\n\n```html\n\u003cx-feed-links /\u003e\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Jolita Grazyte](https://github.com/JolitaGrazyte)\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [Sebastian De Deyne](https://github.com/sebastiandedeyne)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-feed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Flaravel-feed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-feed/lists"}