1. Go to this page and download the library: Download watson/sitemap 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/ */
watson / sitemap example snippets
namespace App\Http\Controllers;
use Sitemap;
class SitemapsController extends Controller
{
public function index()
{
// Get a general sitemap.
Sitemap::addSitemap('/sitemaps/general');
// You can use the route helpers too.
Sitemap::addSitemap(route('sitemaps.posts'));
// Return the sitemap to the client.
return Sitemap::index();
}
}
namespace App\Http\Controllers;
use Post;
use Sitemap;
class SitemapsController extends Controller
{
public function posts()
{
$posts = Post::all();
foreach ($posts as $post) {
Sitemap::addTag(route('posts.show', $post), $post->updated_at, 'daily', '0.8');
}
return Sitemap::render();
}
}
namespace App\Http\Controllers;
use Page;
use Sitemap;
class SitemapsController extends Controller
{
public function pages()
{
$pages = Page::all();
foreach ($pages as $page) {
$tag = Sitemap::addTag(route('pages.show', $page), $page->updated_at, 'daily', '0.8');
foreach ($page->images as $image) {
$tag->addImage($image->url, $image->caption);
}
}
return Sitemap::render();
}
}