PHP code example of webwizardsusa / larafeed

1. Go to this page and download the library: Download webwizardsusa/larafeed library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webwizardsusa / larafeed example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Webwizardsusa\Larafeed\BaseFeedItem;
use Webwizardsusa\Larafeed\Contracts\ProvidesFeedItem;
use Webwizardsusa\Larafeed\FeedItem;

class Post extends Model implements ProvidesFeedItem
{
    use HasFactory;

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }
    public function toFeedItem(): BaseFeedItem
    {
        return FeedItem::make()
            ->link(url('post/' . $this->id))
            ->title($this->title)
            ->author($this->user?->name)
            ->content($this->body)
            ->pubDate($this->created_at);
    }
}


    public function __invoke(Request $request)
    {
        return \Webwizardsusa\Larafeed\Channel::make('Test Feed', $request->fullUrl(), 'Our first feed', Post::query()
            ->with('user')
            ->orderBy('created_at', 'desc')
            ->limit(10)
            ->get());
    }

$channel->iTunesCategory(\Webwizardsusa\Larafeed\ITunes\Categories\Sports::RUNNING);

php artisan vendor:publish --provider="Webwizardsusa\Larafeed\LarafeedServiceProvider" --tag="larafeed"
xml

<itunes:category text="Sports">
    <itunes:category text="Running"/>
</itunes:category>