PHP code example of mateusjatenee / php-json-feed

1. Go to this page and download the library: Download mateusjatenee/php-json-feed 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/ */

    

mateusjatenee / php-json-feed example snippets

   
'providers' => [
    ...
    Mateusjatenee\JsonFeed\JsonFeedServiceProvider::class,
];
   
'aliases' => [
    ...
    'JsonFeed' => Mateusjatenee\JsonFeed\Facades\JsonFeed::class,
];
   


use Mateusjatenee\JsonFeed\Facades\JsonFeed;

$config = [
    'title' => 'My JSON Feed test',
    'home_page_url' => 'https://mguimaraes.co',
    'feed_url' => 'https://mguimaraes.co/feeds/json',
    'author' => [
        'url' => 'https://twitter.com/mateusjatenee',
        'name' => 'Mateus Guimarães',
    ],
    'icon' => 'https://mguimaraes.co/assets/img/icons/apple-touch-icon-72x72.png',
    'favicon' => 'https://mguimaraes.co/assets/img/icons/favicon.ico',
];

JsonFeed::setConfig($config);

   


namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use JsonFeed;

class JsonFeedController extends Controller
{
    public function index()
    {
        $posts = App\Post::all();

        return JsonFeed::setItems($posts)->toJson();
    }
}

   


namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use JsonFeed;

class JsonFeedController extends Controller
{
    public function index()
    {
        $posts = App\Post::all();

        $config = [
            'title' => 'My JSON Feed test',
            'home_page_url' => 'https://mguimaraes.co',
            'feed_url' => 'https://mguimaraes.co/feeds/json',
            'author' => [
                'url' => 'https://twitter.com/mateusjatenee',
                'name' => 'Mateus Guimarães',
            ],
            'icon' => 'https://mguimaraes.co/assets/img/icons/apple-touch-icon-72x72.png',
            'favicon' => 'https://mguimaraes.co/assets/img/icons/favicon.ico',
        ];

        return JsonFeed::start($config, $posts)->toJson();
    }
}

 bash
$ composer