whisper-money/app/Http/Controllers/SitemapController.php

52 lines
1.5 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Response;
class SitemapController extends Controller
{
public function index(): Response
{
$baseUrl = config('app.url');
$urls = [
[
'loc' => $baseUrl,
'changefreq' => 'weekly',
'priority' => '1.0',
'lastmod' => now()->toW3cString(),
],
[
'loc' => "{$baseUrl}/privacy",
'changefreq' => 'monthly',
'priority' => '0.5',
'lastmod' => now()->toW3cString(),
],
[
'loc' => "{$baseUrl}/terms",
'changefreq' => 'monthly',
'priority' => '0.5',
'lastmod' => now()->toW3cString(),
],
];
$xml = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
$xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
foreach ($urls as $url) {
$xml .= ' <url>'."\n";
$xml .= " <loc>{$url['loc']}</loc>\n";
$xml .= " <lastmod>{$url['lastmod']}</lastmod>\n";
$xml .= " <changefreq>{$url['changefreq']}</changefreq>\n";
$xml .= " <priority>{$url['priority']}</priority>\n";
$xml .= ' </url>'."\n";
}
$xml .= '</urlset>';
return response($xml, 200)
->header('Content-Type', 'application/xml');
}
}