在 laravel 10 app / livewire 3.4 中,我需要添加 feeds 页面和 using 页面 https://laravel-news.com/package/spatie-laravel-feed 作为源数据
我已经安装了“spatie/laravel-feed”:“^4.4”并在文件中添加了我的模型的路径:
'main' => [
'items' => 'App\Models\News@getActiveNewsFeedItems',
并在模型中添加:
use Spatie\Feed\Feedable;
use Spatie\Feed\FeedItem;
class News extends Model implements Feedable
{
protected $primaryKey = 'id';
public $timestamps = false;
protected $table = 'news';
public static function getActiveNewsFeedItems()
{
return News::getByPublished(NewsPublishedEnum::PUBLISHED->value)->limit(50)->orderBy('published', 'desc')->get();
}
public function toFeedItem(): FeedItem
{
return FeedItem::create()
->id($this->slug)
->title($this->title)
->summary($this->content_shortly)
->updated($this->published_at)
->link(route('news.show', $this->slug))
->authorName($this->creator->name)
->authorEmail($this->creator->email);
}
在 resources/views/components/layouts/frontend.blade.php 布局中我添加了:
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap">
<link rel="alternate" type="application/atom+xml" title="News" href="/feeds.main">
不确定,是否必须在上面的代码中添加两行?
但在任何路线上:
http://local-news-publishers.com/feeds.main
http://local-news-publishers.com/feeds
http://local-news-publishers.com/feed
哪里
http://local-news-publishers.com
是我网站的根目录?
我收到错误:
404 NOT FOUND
我在 php artisan route:list 命令的输出中看到输出:
GET|HEAD / ................................................................................................................................... feeds.main › Spatie\Feed › FeedController
出了什么问题?
决定由线决定
@include('feed::links')
在我的布局中我必须更改选项
'url' => '/feed',
在文件 config/feed.php 中
之后喂食就可以了!