Feed Create

This page is under active development.

Example

Here's a complete example:

<?php

namespace App\Http\Controllers;

use App\Post;
use Illuminate\Http\Request;
use Obydul\EasyFeed\Feed;

class FeedController extends Controller
{
    // create feed
    public function create()
    {
        //  Feed object
        $feed = new Feed();
        $feed->title = "Title of the feed";
        $feed->description = "Description of the feed";
        $feed->link = "http://laradev.test";
        $feed->items = array();

        // add image
        $feed->image = array(
            'title' => "Image title",
            'link' => "http://laradev.test/",
            'url' => "http://laradev.test/logo.png"
        );

        // add items to feed
        $items = array(); // create temp array

        $posts = Post::all();
        foreach ($posts as $post) {
            $item = array(
                'title' => $post->title,
                'description' => $post->description,
                'link' => $post->link,
                'pubDate' => $post->pubDate,
                'author' => $post->author,
            );
            array_push($items, $item);
        }

        // add items to feed items
        $feed->items = $items;

        // create
        $data = $feed->create();

        // return response
        return response($data)->header('Content-Type', 'text/xml, charset=utf-8');
    }
}