I'm currently organising Full Stack Europe. It's a conference in Antwerp, Belgium for developers who want to learn across the stack. You can use this link get your ticket with a nice discount.

A package to easily generate feeds in Laravel

Original – by Freek Van der Herten – 2 minute read

Yesterday our newest package laravel-feed was released. It makes generating RSS feeds in Laravel very easy. It's very opinionated to fit the needs of our projects, but I believe lots of other developers will find it useful too. There's almost no coding involved to create some feeds.

Installation encompasses:

  • registering the service provider (you've probably done this a gazillion times by now)
  • publishing a config file
  • calling a route macro in your routes file to register the view routes
  • adding a partial in the head section of your template to display links to the feeds
After you've done that adding feeds to your site is a breeze. You'll only need to add some values to the configuration file. Here's an example:
return [

    'feeds' => [

        [
            /*
             * Here you can specify which class and method will return
             * the items that should appear in the feed. 
             */

            'items' => '\App\News@getAll',
            /*
             * The feed will be available on this url.
             */
            'url' => '/feed',

            ...
        ],
    ],
];

After that you're done. The package will convert all models that are returned by the getAll()-function of the \App\Model-class to feed items. The feed items will be displayed on the /feed url. On all pages a link to that feed will appear in the head section.

Want to know more about the package? Then head over to GitHub to read the readme and view some code. If you like it, maybe one of our other Laravel packages can be of some use to you as well.

Stay up to date with all things Laravel, PHP, and JavaScript.

Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.