PHP code example of fuxu / larasitemap

1. Go to this page and download the library: Download fuxu/larasitemap 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/ */

    

fuxu / larasitemap example snippets


FuXu\LaraSitemap\SitemapServiceProvider::class,

void add(string $loc, string $lastmod, double $priority, string $changefreq)
 
Response render($format)



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;

use FuXu\LaraSitemap\Sitemap;

class SitemapController extends BaseController
{
    public function __construct(Sitemap $sitemap)
    {
        $this->sitemap = $sitemap;
    }

    /**
     * Generate sitemapindex format
     *
     */
    public function index(Request $request)
    {
        $this->sitemap->add(URL::to('sitemap/urlset'));

        return $this->sitemap->render('sitemapindex');
    }

    /**
     * Generate urlset format
     *
     */

    public function urlset(Request $request)
    {
        $this->sitemap->add(URL::to('welcome'));

        return $this->sitemap->render();
    }

}