Skip to content

coderflexx/laravel-feed

Repository files navigation

laravel-rss

Latest Version on Packagist Software License Build Status SensioLabsInsight Quality Score Total Downloads

This package generates rss feeds for any of the models that has a feed data.

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

Install

You can install the package via composer:

$ composer require spatie/laravel-rss

Next up, the service provider must be registered:

// Laravel5: config/app.php
'providers' => [
    ...
    Spatie\Rss\RssServiceProvider::class,

];

Next, you must publish the config file:

php artisan vendor:publish --provider="Spatie\Rss\RssServiceProvider"

This is the content of the published file laravel-rss.php: You must change it to fit your needs.

return [

'feeds' => [
        [
            'items' => '',  // Fill in the class with a method that returns a collection of items that must come in the feed. e.g.: 'App\Repositories\NewsItemRepository@getAllOnline'
            'url'   => '',  // feed url, on which the feeds would be shown

            'meta'  => [
                'link'          => '',
                'title'         => '',
                'updated'       => \Carbon\Carbon::now()->toATOMString(),
                'description'   => '',
            ]

        ],
    ],

];

Usage

The model that would have feeds must implement RssItem interface and have a method called getFeedData that would return array with the specific values as shown in the example here below: e.g.:

  class NewsItem extends ModuleModel implements RssItem
  {
    ...

     public function getFeedData()
        {
            return [
                'title'     => $this->name,
                'id'        => $this->id,
                'updated'   => $this->updated_at,
                'summary'   => $this->present()->excerpt,
                'link'       => action('Front\NewsItemController@detail', [$this->url]),
            ];
        }
  }

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 freek@spatie.be instead of using the issue tracker.

Credits

About Spatie

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

License

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

Packages

No packages published

Languages

  • PHP 90.3%
  • Blade 9.7%