Giter Club home page Giter Club logo

laravel-rss's Introduction

Simple Rss feed for your models

Atom RSS feed for your site. Provides caching of the entire feed for performance.

Install

Configuration

Publish the config

Publish the view if you want to adjust the feed xml

Implement the Interface For Entries

lagbox\rss\Interface\Entriable:

interface Entriable
{
    public function rssTitle();

    public function rssSubTitle();

    public function rssLink();

    public function rssId();

    public function rssAuthor();

    public function rssSummary();

    public function rssUpdated();

    public function rssCategory();
}

Trait

The trait uses an array to map the fields used on your entity. If you want to use the trait to implement rssTitle, rssSubTitle, rssSummary, rssUpdated you should setup your $rssFields array:

protected $rssFields = [
    'title' => 'title',
    'subtitle' => 'sub_title',
    'summary' => 'summary',
    'updated' => 'updated_at',
];

The trait does not provide the methods rssLink, rssAuthor or rssCategory. You will have to implement those methods yourself.

rssLink is for returning a full url to the current entity.

rssAuthor should return an array for the author (name, email) or an empty array.

public function rssAuthor()
{
    return [
        'name' => $this->author->name,
        'email' => $this->author->email,
    ];
}

rssCategory should return the category name or an array of category names the entity belongs too. This could be categories or tags, how ever you have designed your categorizing.

public function rssCategory()
{
    return $this->tags->pluck('name')->all();
}

Controller

use lagbox\rss\Traits\Feedable;

class YourController extends Controller
{
    use Feedable;

    /**
     * Returns a collection of entities of type Entriable.
     *
     * @return \Illuminate\Support\Collection
     */
    protected function getEntities()
    {
        return Post::latest('updated_at')->get();
    }
}

Routes

Route::get('feed', 'YourController@feed');

laravel-rss's People

Contributors

lagbox avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.