Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ludoguenet committed Mar 3, 2024
1 parent 2e6fd17 commit 517ca0d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/Http/Controllers/RSSFeedController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Models\Nudge;
use Illuminate\Http\Response;

class RSSFeedController extends Controller
{
public function __invoke(): Response
{
$nudges = Nudge::latest()->get();

return response()->view('rss', [
'nudges' => $nudges,
])->header('Content-Type', 'text/xml');
}
}
30 changes: 30 additions & 0 deletions resources/views/rss.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?=
'<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL
?>
<rss version="2.0">
<channel>
<title>
<![CDATA[ laranudge.com ]]>
</title>
<link>
<![CDATA[ https://laranudge.com/feed ]]>
</link>
<description>
<![CDATA[ Share your favourite Laravel tips ]]>
</description>
<language>en</language>
<pubDate>{{ now() }}</pubDate>

@foreach($nudges as $nudge)
<item>
<title>
<![CDATA[{{ $nudge->content }}]]>
</title>
<description>
<![CDATA[{!! $nudge->code !!}]]>
</description>
<pubDate>{{ $nudge->created_at->toRssString() }}</pubDate>
</item>
@endforeach
</channel>
</rss>
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
use App\Http\Controllers\Nudge\DestroyController;
use App\Http\Controllers\Nudge\StoreController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\RSSFeedController;
use Illuminate\Support\Facades\Route;

Route::get('/', HomePageController::class)->name('homepage');
Route::get('feed', RSSFeedController::class)->name('rss.feed');

Route::middleware(['auth', 'verified'])->group(function () {
Route::get('/dashboard', DashBoardController::class)->name('dashboard');
Expand Down

0 comments on commit 517ca0d

Please sign in to comment.