PHP code example of paulund / rss-feed
1. Go to this page and download the library: Download paulund/rss-feed library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
paulund / rss-feed example snippets
php artisan make:controller RssFeedController
Route::get('rss', 'RssFeedController@index');
$feedMeta = new FeedMeta(
title: 'RSS Feed Title',
description: 'This RSS feed description',
link: 'https://www.example.com/rss',
pubDate: now()->format(\DateTime::RFC822),
lastBuildDate: now()->toDateTimeString(),
category: 'General',
generator: 'Paulund RSS Feed Generator'
);
$feedItems = $blogPosts->map(function ($post): array {
return [
'title' => $post->title,
'description' => $post->description,
'link' => route('blog.show', $post->slug),
'pubDate' => (new \DateTime($post->date))->format(\DateTime::RFC822),
'category' => $post->category,
];
});
return (new Feed($feedMeta, $feedItems))->toResponse();
namespace App\Http\Controllers;
use App\Models\Post;
use Illuminate\Http\Request;
use Paulund\RssFeed\Feed;
use Paulund\RssFeed\FeedMeta;
class RssFeedController extends Controller
{
public function index()
{
$blogPosts = Post::all();
$feedMeta = new FeedMeta(
title: 'RSS Feed Title',
description: 'This RSS feed description',
link: 'https://www.example.com/rss',
pubDate: now()->format(\DateTime::RFC822),
lastBuildDate: now()->toDateTimeString(),
category: 'General',
generator: 'Paulund RSS Feed Generator'
);
$feedItems = $blogPosts->map(function ($post): array {
return [
'title' => $post->title,
'description' => $post->description,
'link' => route('blog.show', $post->slug),
'pubDate' => (new \DateTime($post->date))->format(\DateTime::RFC822),
'category' => $post->category,
];
});
return (new Feed($feedMeta, $feedItems))->toResponse();
}
}