Add (publish date): Change to datetime, show on view, save publishdate properly
add (composer): rss feed
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Feed\Feedable;
|
||||
use Spatie\Feed\FeedItem;
|
||||
|
||||
/**
|
||||
* Class Post
|
||||
@@ -31,7 +33,7 @@
|
||||
* @property Author|null $author
|
||||
* @property Collection|PostCategory[] $post_categories
|
||||
*/
|
||||
class Post extends Model
|
||||
class Post extends Model implements Feedable
|
||||
{
|
||||
protected $table = 'posts';
|
||||
|
||||
@@ -41,6 +43,7 @@ class Post extends Model
|
||||
'comment_count' => 'int',
|
||||
'likes_count' => 'int',
|
||||
'featured' => 'bool',
|
||||
'publish_date' => 'datetime',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
@@ -98,4 +101,20 @@ public function getFeaturedImageLqipAttribute()
|
||||
// Append "_lqip" before the extension to create the LQIP image URL
|
||||
return str_replace(".{$extension}", "_lqip.{$extension}", $featuredImage);
|
||||
}
|
||||
|
||||
public function toFeedItem(): FeedItem
|
||||
{
|
||||
return FeedItem::create()
|
||||
->id($this->id)
|
||||
->title($this->title)
|
||||
->summary($this->excerpt)
|
||||
->updated($this->publish_date)
|
||||
->link(route('home.country.post', ['country' => $this->post_category?->category?->country_locale_slug, 'post_slug' => $this->slug]))
|
||||
->authorName($this->author->name);
|
||||
}
|
||||
|
||||
public static function getFeedItems()
|
||||
{
|
||||
return Post::where('status', 'publish')->latest()->get();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user