Skip to content

Commit 4f63bf8

Browse files
Refacto feed links
1 parent 816f87c commit 4f63bf8

File tree

4 files changed

+11
-17
lines changed

4 files changed

+11
-17
lines changed

resources/views/feed-links.blade.php

Lines changed: 0 additions & 3 deletions
This file was deleted.

resources/views/links.blade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@foreach($feeds as $name => $title)
2+
<link rel="alternate" type="application/rss+xml" href="{{ route("feeds.{$name}") }}" title="{{ $title }}">
3+
@endforeach

src/FeedServiceProvider.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
namespace Spatie\Feed;
44

5-
use Illuminate\Events\Dispatcher;
5+
use Illuminate\Support\Facades\View;
66
use Illuminate\Support\ServiceProvider;
7-
use Illuminate\View\View;
87
use Spatie\Feed\Helpers\Path;
98
use Spatie\Feed\Http\FeedController;
109

@@ -22,7 +21,7 @@ public function boot()
2221
__DIR__.'/../resources/views' => resource_path('views/vendor/feed'),
2322
], 'views');
2423

25-
$this->bindFeedLinks();
24+
$this->registerLinksComposer();
2625
}
2726

2827
public function register()
@@ -45,17 +44,12 @@ protected function registerRouteMacro()
4544
});
4645
}
4746

48-
public function bindFeedLinks()
47+
public function registerLinksComposer()
4948
{
50-
$this->app->make(Dispatcher::class)->listen('composing: feed::feed-links', function (View $view) {
51-
$feeds = collect(config('feed.feeds'))->map(function ($feedConfig, $index) {
52-
return [
53-
'title' => $feedConfig['title'],
54-
'url' => $this->app['url']->route("feeds.{$index}"),
55-
];
56-
});
57-
58-
$view->with(compact('feeds'));
49+
View::composer('feed::links', function ($view) {
50+
$view->with([
51+
'feeds' => array_pluck(config('feed.feeds'), 'title'),
52+
]);
5953
});
6054
}
6155
}

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function setUpRoutes($app)
6464
$app['router']->feeds('feedBaseUrl');
6565

6666
$app['router']->get('/test-route', function () use ($app) {
67-
return $app['view']->make('feed::feed-links');
67+
return $app['view']->make('feed::links');
6868
});
6969
}
7070

0 commit comments

Comments
 (0)