Skip to content

coderflexx/laravel-feed

Repository files navigation

laravel-feed

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

This package generates rss feeds for any of the chosen models. A model that should have a feed, must implement FeedItem and have all of the corresponding methods.

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-feed

Next up, the service provider must be registered:

'providers' => [
    ...
    Spatie\Feed\FeedServiceProvider::class,

];

Next, you must publish the config file:

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

This is the content of the published file laravel-feed.php:

You must change it to fit your needs.

return [

'feeds' => [
        [
             /**
             * Fill in for items a class with a method that returns a collection of items
             * that you want in the feed.
             * e.g.: 'App\Repositories\NewsItemRepository@getAllOnline'
             * For url fill in a url, on which the feeds will be shown.
             */
             'items' => '',
             'url' => '', 
             'title' => 'This is feed 1 from the unit tests',
             'description' => 'This is feed 1 from the unit tests.',
        
            ],
        ],
    ],

];

Usage

A model that would have feeds must implement FeedItem interface and have all corresponding methods:

e.g.:

  class NewsItem extends ModuleModel implements FeedItem
    {
    ...
        public function getFeedData() : array
        {
            return [
                'title' => $this->getFeedItemTitle(),
                'id' => $this->getFeedItemId(),
                'updated' => $this->getFeedItemUpdated(),
                'summary' => $this->getFeedItemSummary(),
                'link' => $this->getFeedItemLink(),
            ];
        }
  
        public function getFeedItemId()
        {
            return $this->id;
        }
  
        public function getFeedItemTitle() : string
        {
            return $this->name;
        }
  
        public function getFeedItemSummary() : string
        {
            return $this->present()->excerpt;
        }
  
        public function getFeedItemUpdated() : Carbon
        {
            return $this->updated_at;
        }
  
        public function getFeedItemLink() : string
        {
            return 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%