如何将spatie/lavel提要内容类型设置为xml



我将Laravel v8与spatie/lavel feed v4一起使用,代码如下:

路由/web.php

Route::get('feed', 'AppModelsBlogPost@getFeedItems')->name("feeds.main");

config/feed.php

<?php
return [
'feeds' => [
'main' => [
/*
* Here you can specify which class and method will return
* the items that should appear in the feed. For example:
* [AppModel::class, 'getAllFeedItems']
*
* You can also pass an argument to that method.  Note that their key must be the name of the parameter:             *
* [AppModel::class, 'getAllFeedItems', 'parameterName' => 'argument']
*/
'items' => ['AppModelsBlogPost', 'getFeedItems'],
/*
* The feed will be available on this url.
*/
'url' => '/feed',
'title' => 'News',
'description' => 'The description of the feed.',
'language' => 'hu-HU',
/*
* 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' => 'application/atom+xml',
/*
* The content type for the feed response.  Set to an empty string to automatically
* determine the correct value.
*/
'contentType' => '',
],
],
];

网页HTML代码中的结果:

<link rel="alternate" type="application/atom+xml" href="http://mydomain.test/feed" title="News">

但如果我在浏览器中打开链接,结果会包含JSON代码。

如何正确设置/强制设置application/atom+xml内容类型?

错误在路由中

Route::get('feed', 'AppModelsBlogPost@getFeedItems')->name("feeds.main");

所以应该是

Route::get('/feed',FeedController::class)->name("feeds.main");

Route::feeds();

最新更新