How To Create RSS Feed in Laravel 10 Example Tutorial

Reading Time: 6 minutes

RSS (Really Simple Syndication) feeds are a great way to share content and updates from your Laravel 10 application with users and external services. This tutorial will walk you through the process of building an RSS feed in Laravel 10.

Laravel 10 makes it simple to produce and serve RSS feeds, making it simple to keep users and subscribers up to speed on the newest information or updates on your website.

Read More: Laravel 10 Submit Livewire Form Data Tutorial

Here, we will consider some fake posts and create a rss feed of posts.

Let’s get started.

Laravel Installation

Open terminal and run this command to create a laravel project.

composer create-project laravel/laravel myblog

It will create a project folder with name myblog inside your local system.

To start the development server of laravel –

php artisan serve


Assuming laravel already installed inside your system.

Create Database & Connect

To create a database, either we can create via Manual tool of PhpMyadmin or by means of a mysql command.

CREATE DATABASE laravel_app;

To connect database with application, Open .env file from application root. Search for DB_ and update your details.


Setup Model & Migration

Open project into terminal and run this command.

$ php artisan make:model Post -m

This command will create two files.

  • A model file Post.php inside /app/Models folder.
  • A migration file 2023_08_21_031111_create_posts_table.php inside /database/migrations folder.

Read More: Laravel 10 Auth with Livewire Jetstream Tutorial

Open xxx_create_posts_table.php migration file and write this code into it.


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
     * Run the migrations.
    public function up(): void
        Schema::create('posts', function (Blueprint $table) {

     * Reverse the migrations.
    public function down(): void

Run Migration

Back to project terminal and run this command,

$ php artisan migrate

It will run all migrations and create their respective tables.

Open Post.php model file from /app/Models folder.


namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
    use HasFactory;

    protected $fillable = [
        'title', 'slug', 'body'


Setup Post Factory (Test Data)

Open project terminal and run this command.

$ php artisan make:factory PostFactory

It will create a file PostFactory.php file inside /database/factories folder.

Read More: Laravel 10 API Testing Tool Package Tutorial

Open file and write this complete code into it.


namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Post>
class PostFactory extends Factory
     * Define the model's default state.
     * @return array<string, mixed>
    public function definition(): array
        return [
            'title' => $this->faker->text(),
            'slug' => Str::slug($this->faker->text()),
            'body' => $this->faker->paragraph()

Process of Data Seeding (Run Factory File)

Back to project terminal and execute these commands –

$ php artisan tinker

It will open tinker shell.

Next, run this command to create 50 fake rows for posts table.

>>> App\Models\Post::factory()->count(50)->create();

Create Controller

Back to terminal and run this artisan command,

$ php artisan make:controller RSSController

It will create RSSController.php file inside /app/Http/Controllers folder.


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Post;

class RSSController extends Controller
    public function index()
        $posts = Post::latest()->get();

        return response()->view('rss', [
            'posts' => $posts
        ])->header('Content-Type', 'text/xml');

Create Template File

Create a file rss.blade.php inside /resources/views folder.

Open file and write this code into it.

'<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
<rss version="2.0">
            <![CDATA[ ]]>
        <![CDATA[ ]]>
            <![CDATA[ Best Blog for Programming Articles ]]>
        <pubDate>{{ now() }}</pubDate>

        @foreach ($posts as $post)
                <![CDATA[{{ $post->title }}]]>
            <link>{{ $post->slug }}</link>
                <![CDATA[{!! $post->body !!}]]>
            <category>{{ $post->category }}</category>
                <![CDATA[Sanjay Kumar]]>
            <guid>{{ $post->id }}</guid>
            <pubDate>{{ $post->created_at->toRssString() }}</pubDate>

Add Route

Open web.php file from /routes folder. Add this given route into it.


use App\Http\Controllers\RSSFeedController;

Route::get('feed', [RSSFeedController::class, 'index']);


Application Testing

Run this command into project terminal to start development server,

php artisan serve

Read More: Laravel 10 How To Get Logged In User Data Tutorial


We hope this article helped you to learn about How To Create RSS Feed in Laravel 10 Example Tutorial in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more