🚀 Hostinger Optimized
🖥️ Server: LiteSpeed
💻 System: Linux s20058.bom1.stableserver.net 5.14.0-611.55.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 19 15:19:29 EDT 2026 x86_64
👤 User: skhata (1324)
🐘 PHP: 8.4.20
🚫 Disabled: ✨ NONE

💻 Terminal

📁 /home/skhata/chandrasons.com/public
$

📄 SitemapController.php

📁 Path: /home/skhata/chandrasons.com/app/Http/Controllers/SitemapController.php
📊 Size: 2.25 KB
🔒 Perm: 0644
📝 MIME: text/x-php
<?php
namespace App\Http\Controllers;

use App\Models\Service;
use App\Models\ProductCategory;
use App\Models\BlogPost;
use Illuminate\Http\Response;

class SitemapController extends Controller {
    public function index(): Response {
        $langs = ['en', 'ne', 'hi'];
        $staticPages = ['/', '/about', '/services', '/products', '/brand-partners', '/faqs', '/blog', '/contact', '/why-sunauli'];

        $urls = [];

        foreach ($langs as $lang) {
            foreach ($staticPages as $page) {
                $urls[] = ['loc' => url("/{$lang}{$page}"), 'changefreq' => $page === '/' ? 'daily' : 'weekly', 'priority' => $page === '/' ? '1.0' : '0.8'];
            }
            foreach (Service::where('is_active', true)->get() as $service) {
                $urls[] = ['loc' => url("/{$lang}/services/{$service->slug}"), 'changefreq' => 'monthly', 'priority' => '0.7'];
            }
            foreach (ProductCategory::where('is_active', true)->get() as $cat) {
                $urls[] = ['loc' => url("/{$lang}/products/{$cat->slug}"), 'changefreq' => 'weekly', 'priority' => '0.6'];
            }
        }
        foreach (BlogPost::published()->get() as $post) {
            $urls[] = ['loc' => url("/en/blog/{$post->slug}"), 'changefreq' => 'monthly', 'priority' => '0.5', 'lastmod' => $post->updated_at->toDateString()];
        }

        $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
        $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">' . "\n";
        foreach ($urls as $url) {
            $xml .= "  <url>\n";
            $xml .= "    <loc>{$url['loc']}</loc>\n";
            if (isset($url['lastmod'])) $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, ['Content-Type' => 'application/xml']);
    }

    public function robots(): Response {
        $content = "User-agent: *\nAllow: /\nDisallow: /admin\nDisallow: /admin/*\n\nSitemap: " . url('/sitemap.xml');
        return response($content, 200, ['Content-Type' => 'text/plain']);
    }
}
← Back📥 Raw✏️ Edit🔒 Chmod
✨ File Manager Magic ✨