Files
core/app/Http/Controllers/Sitemap.php
T

58 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Models\Content;
class Sitemap extends Controller
{
/**
* @var Content
*/
private $content;
/**
* Sitemap constructor.
*
* @param Content $content
*/
public function __construct(Content $content)
{
$this->content = $content;
}
/**
* Get sitemap for all content pages
*
* @return mixed
*/
public function getMap()
{
// load all public pages
$pages = $this->content->getPageQuery()
->get();
// iterate over all pages and add tag for each of them
foreach ($pages as $page) {
// is this page a homepage? because of URL
if ($page->is_homepage) {
$route = route('page.index');
$priority = 1;
} else {
$route = route('page.content', ['url' => $page->url]);
$priority = 0.8;
}
// add to all pages
\Sitemap::addTag($route, $page->updated_at, 'daily', $priority);
}
// print sitemap
return \Sitemap::render();
}
}