Laravel RSS Feed Tutorial With Example

Hello developers, In this example, I will describe to you how to do Laravel RSS Feed Tutorial With Example. Creating an RSS feed in Laravel isn’t the difficult task, but using a package and a few hints can help you create an RSS feed relatively quick. We are going to use the roumen/feed package to walk through going from a brand new Laravel 5.6 application to serving RSS feeds. Currently, this package supports only RSS and Atom, and make Atom the default choice.

RSS stands for Rich Site Summary. It is often called Really Simple Syndication is a type of web feed. Websites usually use RSS feeds to publish regularly updated information, such as blog entries, news headlines, audio, video. RSS also feeds useful for users who want to receive timely updates from popular websites or to aggregate data from many sites.

There are thousands of application such as  Apple News, Google Newsstand, Feedly that allows people to follow and read your content whenever new content is published. Feeds allow webmasters to drive traffic to their website.

Laravel RSS Feed Tutorial With Example

We are going to Configure Laravel Project.

#1: Download Laravel Application

Establish  Laravel Application by the typing following command.

composer create-project --prefer-dist laravel/laravel laravelrssfeed

#2: Configure SQL Database

Now we can setup database credentials.


#3: Install roumen/feed Package

First, install the roumen/feed package via the Composer package manager.

composer require roumen/feed

Or add the following to your composer.json file :

For Laravel 5.6

"roumen/feed": "2.12.*"

For Laravel 5.5

"roumen/feed": "2.11.*"

For Laravel 5.4 and lower

"roumen/feed": "2.10.*"

If you are using laravel 5.5 or higher you can skip the service provider registration.

Let’s Add ServiceProvider in config/app.php

'providers' => [

Let’s Add an alias config/app.php

'aliases' => [
               'Feed' => Roumen\Feed\Feed::class,

#4: Build Model and Migration File

php artisan make:model Post -m

It will create a Post.php file and also create a create_posts_table.php  migration file.


public function up()
        Schema::create('posts', function (Blueprint $table) {

Save and run.

php artisan migrate

#5: Create Dummy data

Next up, open the database/factories/UserFactory.php file and add the following:

$factory->define(App\Post::class, function (Faker $faker) {
    return [
        'title' => $faker->title,
        'slug' => $faker->slug,
        'author' => $faker->title,
        'description' => $faker->text,
        'content' => $faker->text,

Run below command in terminal

php artisan tinker
factory(App\Post::class, 50)->create();

Now you can see database post table have 50 records.


laravel rssfeed example

#6: Create one controller

$ php artisan make:controller PostController

It will build a controller file called PostController.php.



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use FarhanWazir\GoogleMaps\GMaps;

class PostController extends Controller
    public function render()
        /* create new feed */
    $feed = \App::make("feed");
     /* cache the feed for 60 minutes */
    if (!$feed->isCached())
    /* creating rss feed with our most recent 10 posts */
    $posts = \DB::table('posts')->orderBy('created_at', 'desc')->take(20)->get();
    /* set your feed's title, description, link, pubdate and language */
    $feed->title = 'Hello';
    $feed->description = 'Investmentnovel';
    $feed->logo = '';
    $feed->link = url('feed');
    $feed->pubdate = $posts[0]->created_at;
    $feed->lang = 'en';

    foreach ($posts as $post)
        $feed->add($post->title, $post->author, \URL::to($post->slug), $post->created_at, $post->description, $post->content);
    return $feed->render('atom');

#7: Define Route

We register route in a web.php file.

Route::get('feed', 'PostController@render');

Our feed should be available at  http://localhost:8000/feed now.


How to Generate RSS Feed in Laravel Example

#8: Linking to the Feed

You can add an RSS link to the welcome page by adding Feed:: link  in the <head> of the view:


        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        {!!Feed::link(url('feed'), 'atom', 'My Feed')!!}

If you go to the homepage of the project, you’ll get something like the following linktag:

<link rel="alternate" type="application/atom+xml" href="http://localhost:8000/feed" title="My Feed">

Paste this url in your browser view-source:http://localhost:8000/. You can see below screen.


How To Create RSS Feed in Laravel Tutorial With Example

At last, our Laravel RSS Feed Tutorial With Example is over.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.