Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion app/Models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Laravel\Scout\Searchable;
use Spatie\Feed\Feedable;
use Spatie\Feed\FeedItem;

final class Article extends Model
final class Article extends Model implements Feedable
{
use HasFactory;
use HasAuthor;
Expand All @@ -28,6 +31,8 @@ final class Article extends Model

const TABLE = 'articles';

const FEED_PAGE_SIZE = 20;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -319,4 +324,21 @@ public static function nextForSharing(): ?self
->orderBy('submitted_at', 'asc')
->first();
}

public static function getFeedItems(): Collection
{
return self::paginate(self::FEED_PAGE_SIZE)
->getCollection();
}

public function toFeedItem(): FeedItem
{
return FeedItem::create()
->id($this->id())
->title($this->title())
->summary($this->excerpt())
->updated($this->updatedAt())
->link(route('articles', $this->slug()))
->authorName($this->author()->name());
}
}
51 changes: 51 additions & 0 deletions config/feed.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Models\Article;
use App\Models\Thread;

return [
Expand Down Expand Up @@ -53,5 +54,55 @@
*/
'contentType' => '',
],

'articles' => [
/*
* Here you can specify which class and method will return
* the items that should appear in the feed. For example:
* [App\Model::class, 'getAllFeedItems']
*
* You can also pass an argument to that method. Note that their key must be the name of the parameter:
* [App\Model::class, 'getAllFeedItems', 'parameterName' => 'argument']
*/
'items' => [Article::class, 'getFeedItems'],

/*
* The feed will be available on this url.
*/
'url' => '/articles/feed',

'title' => 'Laravel.io Articles RSS Feed',
'description' => 'The RSS feed for Laravel.io articles contains a list of all articles posted by community members.',
'language' => 'en-US',

/*
* The image to display for the feed. For Atom feeds, this is displayed as
* a banner/logo; for RSS and JSON feeds, it's displayed as an icon.
* An empty value omits the image attribute from the feed.
*/
'image' => '',

/*
* The format of the feed. Acceptable values are 'rss', 'atom', or 'json'.
*/
'format' => 'atom',

/*
* The view that will render the feed.
*/
'view' => 'feed::atom',

/*
* The mime type to be used in the <link> tag. Set to an empty string to automatically
* determine the correct value.
*/
'type' => '',

/*
* The content type for the feed response. Set to an empty string to automatically
* determine the correct value.
*/
'contentType' => '',
],
],
];
7 changes: 7 additions & 0 deletions resources/views/articles/overview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@
<div class="mt-6">
<x-moderators :moderators="$moderators" />
</div>

<div class="hidden lg:block mt-6">
<x-buttons.dark-cta class="w-full" href="{{ url('/articles/feed') }}">
<x-heroicon-s-rss class="w-6 h-6 mr-2" />
RSS Feed
</x-buttons.dark-cta>
</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/forum/overview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
</div>

<div class="hidden lg:block mt-6">
<x-buttons.dark-cta class="w-full">
<x-buttons.dark-cta class="w-full" href="{{ url('/forum/feed') }}">
<x-heroicon-s-rss class="w-6 h-6 mr-2" />
RSS Feed
</x-buttons.dark-cta>
Expand Down