phplaravelfeed

Why after adding /spatie-laravel-feed plugin nothig is opened?


In laravel 10 app / livewire 3.4 I need to add feeds page and using page https://laravel-news.com/package/spatie-laravel-feed as source data

I have installed "spatie/laravel-feed": "^4.4" and in file added path to my model:

'main' => [
    'items' => 'App\Models\News@getActiveNewsFeedItems',

and in model added :

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);
    }

In layout of resources/views/components/layouts/frontend.blade.php I added :

<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">

Not sure, if I have to add both 2 lines in code above ?

But on any of routes :

http://local-news-publishers.com/feeds.main

http://local-news-publishers.com/feeds

http://local-news-publishers.com/feed

where http://local-news-publishers.com is root of my site? I got error :

404 NOT FOUND

I see output in output of php artisan route:list command :

  GET|HEAD  / ................................................................................................................................... feeds.main › Spatie\Feed › FeedController

What is wrong ?


Solution

  • Decision is with line

    @include('feed::links')
    

    in my layout I had to change option

    'url' => '/feed',
    

    in file config/feed.php

    After that feeds work ok!