All Projects → spatie → Laravel Feed

spatie / Laravel Feed

Licence: mit
Easily generate RSS feeds

Projects that are alternatives of or similar to Laravel Feed

Front End Rss
📙 根据 RSS 抓取最新前端技术文章,来源:前端早读课、前端大全、前端之巅、淘宝前端、张鑫旭博客、凹凸实验室等
Stars: ✭ 418 (-27.05%)
Mutual labels:  blog, rss, feed
Xity Starter
A blog-ready 11ty starter based on PostCSS, with RSS feed and Native Elements!
Stars: ✭ 184 (-67.89%)
Mutual labels:  blog, rss, feed
Blogetc
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.
Stars: ✭ 198 (-65.45%)
Mutual labels:  blog, rss, laravel
Laravel Feed
Laravelium Feed package for Laravel.
Stars: ✭ 356 (-37.87%)
Mutual labels:  laravel, feed
Api.rss
RSS as RESTful. This service allows you to transform RSS feed into an awesome API.
Stars: ✭ 340 (-40.66%)
Mutual labels:  rss, feed
Podcastgenerator
Open Source Podcast Publishing Solution since 2006
Stars: ✭ 344 (-39.97%)
Mutual labels:  rss, feed
Borgert Cms
Borgert is a CMS Open Source created with Laravel Framework 5.6
Stars: ✭ 298 (-47.99%)
Mutual labels:  blog, laravel
Freek.dev
The sourcecode of freek.dev
Stars: ✭ 407 (-28.97%)
Mutual labels:  blog, laravel
Hexo Generator Feed
Feed generator for Hexo.
Stars: ✭ 400 (-30.19%)
Mutual labels:  rss, feed
Android Dev Sources
All those Android development sources that you need to be and stay awesome!
Stars: ✭ 434 (-24.26%)
Mutual labels:  blog, rss
Laravel Bjyblog
laravel v8 blog
Stars: ✭ 469 (-18.15%)
Mutual labels:  blog, laravel
Elixir Scrape
Scrape any website, article or RSS/Atom Feed with ease!
Stars: ✭ 306 (-46.6%)
Mutual labels:  rss, feed
Moell Blog
基于 Laravel 开发,支持 Markdown 语法的博客
Stars: ✭ 301 (-47.47%)
Mutual labels:  blog, laravel
Reader
Free and open source feeds reader, including all major Google Reader features
Stars: ✭ 347 (-39.44%)
Mutual labels:  rss, feed
Stream Laravel
Laravel Client - Build Activity Feeds & Streams with GetStream.io
Stars: ✭ 299 (-47.82%)
Mutual labels:  laravel, feed
Jquery Rss
An easy-to-use rss plugin for jquery with templating.
Stars: ✭ 443 (-22.69%)
Mutual labels:  rss, feed
Cms
Decoupled CMS for any Laravel app, gain control of: pages, blogs, galleries, events, images, custom modules and more.
Stars: ✭ 498 (-13.09%)
Mutual labels:  blog, laravel
Feed
A RSS, Atom and JSON Feed generator for Node.js, making content syndication simple and intuitive! 🚀
Stars: ✭ 523 (-8.73%)
Mutual labels:  rss, feed
Infomate.club
RSS feed collections with article summarization
Stars: ✭ 255 (-55.5%)
Mutual labels:  rss, feed
Freshrss
A free, self-hostable aggregator…
Stars: ✭ 3,793 (+561.95%)
Mutual labels:  rss, feed

Generate RSS feeds in a Laravel app

Latest Version on Packagist MIT Licensed GitHub Workflow Status Total Downloads

This package provides an easy way to generate RSS feeds. There's almost no coding required on your part. Just follow the installation instructions update your config file and you're good to go.

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We 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. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/laravel-feed

Register the routes the feeds will be displayed on using the feeds-macro.

// In routes/web.php
Route::feeds();

You can pass a string as a first argument of the macro. The string will be used as a url prefix for your feed.

Next, you must publish the config file:

php artisan vendor:publish --provider="Spatie\Feed\FeedServiceProvider" --tag="config"

Here's what that looks like:

return [
    'feeds' => [
        'main' => [
            /*
             * Here you can specify which class and method will return
             * the items that should appear in the feed. For example:
             * 'App\[email protected]'
             *
             * You can also pass an argument to that method:
             * ['App\[email protected]', 'argument']
             */
            'items' => '',

            /*
             * The feed will be available on this url.
             */
            'url' => '',

            'title' => 'My feed',
            'description' => 'The description of the feed.',
            'language' => 'en-US',

            /*
             * The view that will render the feed.
             */
            'view' => 'feed::feed',
        ],
    ],
];

Optionally you can publish the view files:

php artisan vendor:publish --provider="Spatie\Feed\FeedServiceProvider" --tag="views"

Usage

Imagine you have a model named NewsItem that contains records that you want to have displayed in the feed.

First you must implement the Feedable interface on that model. Feedable expects one method: toFeedItem, which should return a FeedItem instance.

// app/NewsItem.php

use Illuminate\Database\Eloquent\Model;
use Spatie\Feed\Feedable;
use Spatie\Feed\FeedItem;

class NewsItem extends Model implements Feedable
{
    public function toFeedItem(): FeedItem
    {
        return FeedItem::create()
            ->id($this->id)
            ->title($this->title)
            ->summary($this->summary)
            ->updated($this->updated_at)
            ->link($this->link)
            ->author($this->author);
    }
}

If you prefer, returning an associative array with the necessary keys will do the trick too.

// app/NewsItem.php

use Illuminate\Database\Eloquent\Model;
use Spatie\Feed\Feedable;
use Spatie\Feed\FeedItem;

class NewsItem extends Model implements Feedable
{
    public function toFeedItem(): FeedItem
    {
        return FeedItem::create([
            'id' => $this->id,
            'title' => $this->title,
            'summary' => $this->summary,
            'updated' => $this->updated_at,
            'link' => $this->link,
            'author' => $this->author,
        ]);
    }
}

Next, you'll have to create a method that will return all the items that must be displayed in the feed. You can name that method anything you like and you can do any query you want.

// app/NewsItem.php

public static function getFeedItems()
{
   return NewsItem::all();
}

Finally, you have to put the name of your class and the url where you want the feed to rendered in the config file:

// config/feed.php

return [

    'feeds' => [
        'news' => [
            /*
             * Here you can specify which class and method will return
             * the items that should appear in the feed. For example:
             * '\App\[email protected]'
             */
            'items' => 'App\[email protected]',

            /*
             * The feed will be available on this url.
             */
            'url' => '/feed',

            'title' => 'All newsitems on mysite.com',

            /*
             * Custom view for the items.
             *
             * Defaults to feed::feed if not present.
             */
            'view' => 'feed::feed',
        ],
    ],

];

The items key must point to a method that returns one of the following:

  • An array or collection of Feedables
  • An array or collection of FeedItems
  • An array or collection of arrays containing feed item values

Customizing your feed views

This package provides, out of the box, the feed::feed view that displays your feeds details.

However, you could use a custom view per feed by providing a view key inside of your feed configuration.

In the following example, we're using the previous News feed with a custom feeds.news view (located on resources/views/feeds/news.blade.php):

// config/feed.php

return [

    'feeds' => [
        'news' => [
            'items' => 'App\[email protected]',

            'url' => '/feed',

            'title' => 'All newsitems on mysite.com',

            /*
             * Custom view for the items.
             *
             * Defaults to feed::feed if not present.
             */
            'view' => 'feeds.news',
        ],
    ],

];

Automatically generate feed links

To discover a feed, feed readers are looking for a tag in the head section of your html documents that looks like this:

<link rel="alternate" type="application/atom+xml" title="News" href="/feed">

You can add this to your <head> through a partial view.

 @include('feed::links')

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].