【发布时间】:2021-06-29 08:10:56
【问题描述】:
我将 Laravel v8 与 spatie/laravel-feed v4 一起使用,代码如下:
routes/web.php
Route::get('feed', '\App\Models\Blog\Post@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:
* [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' => ['App\Models\Blog\Post', '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 内容类型?
【问题讨论】:
-
更新
'contentType' => 'application/xml' -
@RamanathMandal 感谢建议,但无济于事
-
@netdjw.i 已检查其返回的 xml。尝试清除视图或更改浏览器
-
@JohnLobo 我试过了,但没有帮助,我仍然得到 JSON 格式
-
@netdjw.strange 我已经在 laravel 8 中尝试过它的工作
标签: laravel rss laravel-8 content-type