ÿþ<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\Response; use Spatie\Sitemap\Sitemap; use Spatie\Sitemap\SitemapIndex; use Spatie\Sitemap\Tags\Url; use App\Models\Motorcycle; use App\Models\Brand; use App\Models\BikeType; use App\Models\Blog; use App\Models\BlogCategory; use App\Models\Showroom; use App\Models\BikeComparison; use Carbon\Carbon; class SitemapController extends Controller { /** * Get the production URL for sitemap generation */ private function getSitemapUrl($path = '') { $baseUrl = 'https://www.bikersbuddy.com'; return $baseUrl . $path; } /** * Generate sitemap index (main index showing all sitemap files) */ public function index() { // Clear any output buffer to prevent XML declaration errors if (ob_get_level()) { ob_clean(); } $sitemapIndex = SitemapIndex::create(); // Add all sitemap files with their last modification dates // Brands sitemap if (Brand::active()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/brands.xml'), Brand::active()->latest('updated_at')->first()->updated_at); } // Motorcycles sitemap if (Motorcycle::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/motorcycle.xml'), Motorcycle::published()->latest('updated_at')->first()->updated_at); } // Specifications sitemap if (Motorcycle::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/specifications.xml'), Motorcycle::published()->latest('updated_at')->first()->updated_at); } // Pages sitemap $sitemapIndex->add($this->getSitemapUrl('/pages.xml'), Carbon::now()); // Bike types sitemap if (BikeType::active()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/bike-type.xml'), BikeType::active()->latest('updated_at')->first()->updated_at); } // Showrooms sitemap if (Showroom::where('is_active', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/showroom.xml'), Showroom::where('is_active', true)->latest('updated_at')->first()->updated_at); } // Blog sitemap if (Blog::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/blog.xml'), Blog::published()->latest('updated_at')->first()->updated_at); } // Blog categories sitemap if (BlogCategory::where('is_active', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/blog-category.xml'), BlogCategory::where('is_active', true)->latest('updated_at')->first()->updated_at); } // Comparisons sitemap if (BikeComparison::where('is_published', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/comparsion.xml'), BikeComparison::where('is_published', true)->latest('updated_at')->first()->updated_at); } return response($sitemapIndex->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate brands sitemap */ public function brands() { $sitemap = Sitemap::create(); $brands = Brand::active() ->orderBy('updated_at', 'desc') ->get(); foreach ($brands as $brand) { $sitemap->add( Url::create($this->getSitemapUrl("/brand/{$brand->slug}")) ->setLastModificationDate($brand->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.8) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate motorcycles sitemap */ public function motorcycles() { $sitemap = Sitemap::create(); $motorcycles = Motorcycle::published() ->with('brand') ->orderBy('updated_at', 'desc') ->get(); foreach ($motorcycles as $motorcycle) { $sitemap->add( Url::create($this->getSitemapUrl("/motorcycle/{$motorcycle->slug}")) ->setLastModificationDate($motorcycle->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.9) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate specifications sitemap */ public function specifications() { // Complete bypass of Laravel response system try { // Clean all output buffers aggressively while (ob_get_level()) { ob_end_clean(); } // Disable all error output error_reporting(0); ini_set('display_errors', 0); ini_set('log_errors', 0); // Disable session writes to prevent session cookies if (session_status() === PHP_SESSION_ACTIVE) { session_write_close(); } // Get motorcycles data $motorcycles = Motorcycle::published() ->select('slug', 'updated_at') ->orderBy('updated_at', 'desc') ->get(); // Generate XML manually to avoid any library interference $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n"; foreach ($motorcycles as $motorcycle) { $lastmod = $motorcycle->updated_at->toAtomString(); $xml .= ' <url>' . "\n"; $xml .= ' <loc>https://www.bikersbuddy.com/reviews/' . $motorcycle->slug . '/specifications</loc>' . "\n"; $xml .= ' <lastmod>' . $lastmod . '</lastmod>' . "\n"; $xml .= ' <changefreq>weekly</changefreq>' . "\n"; $xml .= ' <priority>0.8</priority>' . "\n"; $xml .= ' </url>' . "\n"; } $xml .= '</urlset>'; // Send headers manually header('Content-Type: application/xml; charset=UTF-8'); header('Cache-Control: public, max-age=3600'); header('X-Content-Type-Options: nosniff'); // Output and terminate completely echo $xml; exit; } catch (\Exception $e) { // Emergency fallback while (ob_get_level()) { ob_end_clean(); } header('Content-Type: application/xml; charset=UTF-8'); echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>'; exit; } } /** * Generate pages sitemap */ public function pages() { $sitemap = Sitemap::create(); // Homepage $sitemap->add( Url::create($this->getSitemapUrl('/')) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_DAILY) ->setPriority(1.0) ); // Static pages $staticPages = [ ['url' => '/brands', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/new-bikes', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/comparison', 'priority' => 0.7, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/showrooms', 'priority' => 0.7, 'frequency' => Url::CHANGE_FREQUENCY_MONTHLY], ['url' => '/blog', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_DAILY], ['url' => '/bike-price-in-bangladesh', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ]; foreach ($staticPages as $page) { $sitemap->add( Url::create($this->getSitemapUrl($page['url'])) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency($page['frequency']) ->setPriority($page['priority']) ); } // Price range pages $priceRanges = [ 'under-80000' => 'Under 80,000', '1-lakh' => '1 Lakh', '1-5-lakh' => '1.5 Lakh', '2-lakh' => '2 Lakh', '3-lakh' => '3 Lakh', '4-lakh' => '4 Lakh', '5-lakh' => '5 Lakh', 'above-5-lakh' => 'Above 5 Lakh' ]; foreach ($priceRanges as $slug => $name) { $sitemap->add( Url::create($this->getSitemapUrl("/bikes/price/{$slug}")) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } // Displacement pages $displacements = ['100cc', '125cc', '150cc', '160cc', '200cc', '250cc', '300cc', '400cc', '500cc', '600cc', '1000cc']; foreach ($displacements as $displacement) { $sitemap->add( Url::create($this->getSitemapUrl("/bikes/displacement/{$displacement}")) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate bike types sitemap */ public function bikeTypes() { $sitemap = Sitemap::create(); $bikeTypes = BikeType::active() ->orderBy('updated_at', 'desc') ->get(); foreach ($bikeTypes as $bikeType) { $sitemap->add( Url::create($this->getSitemapUrl("/type/{$bikeType->slug}")) ->setLastModificationDate($bikeType->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate showrooms sitemap */ public function showrooms() { $sitemap = Sitemap::create(); $showrooms = Showroom::where('is_active', true) ->orderBy('updated_at', 'desc') ->get(); foreach ($showrooms as $showroom) { $sitemap->add( Url::create($this->getSitemapUrl("/showroom/{$showroom->slug}")) ->setLastModificationDate($showroom->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_MONTHLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate blog sitemap */ public function blogs() { $sitemap = Sitemap::create(); $blogs = Blog::published() ->orderBy('updated_at', 'desc') ->get(); foreach ($blogs as $blog) { $sitemap->add( Url::create($this->getSitemapUrl("/blog/{$blog->slug}")) ->setLastModificationDate($blog->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_MONTHLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate blog categories sitemap */ public function blogCategories() { $sitemap = Sitemap::create(); $blogCategories = BlogCategory::where('is_active', true) ->orderBy('updated_at', 'desc') ->get(); foreach ($blogCategories as $category) { $sitemap->add( Url::create($this->getSitemapUrl("/blog/category/{$category->slug}")) ->setLastModificationDate($category->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate comparisons sitemap */ public function comparisons() { $sitemap = Sitemap::create(); $comparisons = BikeComparison::where('is_published', true) ->with(['bike1', 'bike2']) ->orderBy('updated_at', 'desc') ->get(); foreach ($comparisons as $comparison) { $sitemap->add( Url::create($this->getSitemapUrl("/comparison/{$comparison->bike1->slug}/vs/{$comparison->bike2->slug}")) ->setLastModificationDate($comparison->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } } ÿþ<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\Response; use Spatie\Sitemap\Sitemap; use Spatie\Sitemap\SitemapIndex; use Spatie\Sitemap\Tags\Url; use App\Models\Motorcycle; use App\Models\Brand; use App\Models\BikeType; use App\Models\Blog; use App\Models\BlogCategory; use App\Models\Showroom; use App\Models\BikeComparison; use Carbon\Carbon; class SitemapController extends Controller { /** * Get the production URL for sitemap generation */ private function getSitemapUrl($path = '') { $baseUrl = 'https://www.bikersbuddy.com'; return $baseUrl . $path; } /** * Generate sitemap index (main index showing all sitemap files) */ public function index() { // Clear any output buffer to prevent XML declaration errors if (ob_get_level()) { ob_clean(); } $sitemapIndex = SitemapIndex::create(); // Add all sitemap files with their last modification dates // Brands sitemap if (Brand::active()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/brands.xml'), Brand::active()->latest('updated_at')->first()->updated_at); } // Motorcycles sitemap if (Motorcycle::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/motorcycle.xml'), Motorcycle::published()->latest('updated_at')->first()->updated_at); } // Specifications sitemap if (Motorcycle::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/specifications.xml'), Motorcycle::published()->latest('updated_at')->first()->updated_at); } // Pages sitemap $sitemapIndex->add($this->getSitemapUrl('/pages.xml'), Carbon::now()); // Bike types sitemap if (BikeType::active()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/bike-type.xml'), BikeType::active()->latest('updated_at')->first()->updated_at); } // Showrooms sitemap if (Showroom::where('is_active', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/showroom.xml'), Showroom::where('is_active', true)->latest('updated_at')->first()->updated_at); } // Blog sitemap if (Blog::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/blog.xml'), Blog::published()->latest('updated_at')->first()->updated_at); } // Blog categories sitemap if (BlogCategory::where('is_active', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/blog-category.xml'), BlogCategory::where('is_active', true)->latest('updated_at')->first()->updated_at); } // Comparisons sitemap if (BikeComparison::where('is_published', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/comparsion.xml'), BikeComparison::where('is_published', true)->latest('updated_at')->first()->updated_at); } return response($sitemapIndex->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate brands sitemap */ public function brands() { $sitemap = Sitemap::create(); $brands = Brand::active() ->orderBy('updated_at', 'desc') ->get(); foreach ($brands as $brand) { $sitemap->add( Url::create($this->getSitemapUrl("/brand/{$brand->slug}")) ->setLastModificationDate($brand->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.8) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate motorcycles sitemap */ public function motorcycles() { $sitemap = Sitemap::create(); $motorcycles = Motorcycle::published() ->with('brand') ->orderBy('updated_at', 'desc') ->get(); foreach ($motorcycles as $motorcycle) { $sitemap->add( Url::create($this->getSitemapUrl("/motorcycle/{$motorcycle->slug}")) ->setLastModificationDate($motorcycle->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.9) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate specifications sitemap */ public function specifications() { // Complete bypass of Laravel response system try { // Clean all output buffers aggressively while (ob_get_level()) { ob_end_clean(); } // Disable all error output error_reporting(0); ini_set('display_errors', 0); ini_set('log_errors', 0); // Disable session writes to prevent session cookies if (session_status() === PHP_SESSION_ACTIVE) { session_write_close(); } // Get motorcycles data $motorcycles = Motorcycle::published() ->select('slug', 'updated_at') ->orderBy('updated_at', 'desc') ->get(); // Generate XML manually to avoid any library interference $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n"; foreach ($motorcycles as $motorcycle) { $lastmod = $motorcycle->updated_at->toAtomString(); $xml .= ' <url>' . "\n"; $xml .= ' <loc>https://www.bikersbuddy.com/reviews/' . $motorcycle->slug . '/specifications</loc>' . "\n"; $xml .= ' <lastmod>' . $lastmod . '</lastmod>' . "\n"; $xml .= ' <changefreq>weekly</changefreq>' . "\n"; $xml .= ' <priority>0.8</priority>' . "\n"; $xml .= ' </url>' . "\n"; } $xml .= '</urlset>'; // Send headers manually header('Content-Type: application/xml; charset=UTF-8'); header('Cache-Control: public, max-age=3600'); header('X-Content-Type-Options: nosniff'); // Output and terminate completely echo $xml; exit; } catch (\Exception $e) { // Emergency fallback while (ob_get_level()) { ob_end_clean(); } header('Content-Type: application/xml; charset=UTF-8'); echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>'; exit; } } /** * Generate pages sitemap */ public function pages() { $sitemap = Sitemap::create(); // Homepage $sitemap->add( Url::create($this->getSitemapUrl('/')) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_DAILY) ->setPriority(1.0) ); // Static pages $staticPages = [ ['url' => '/brands', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/new-bikes', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/comparison', 'priority' => 0.7, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/showrooms', 'priority' => 0.7, 'frequency' => Url::CHANGE_FREQUENCY_MONTHLY], ['url' => '/blog', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_DAILY], ['url' => '/bike-price-in-bangladesh', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ]; foreach ($staticPages as $page) { $sitemap->add( Url::create($this->getSitemapUrl($page['url'])) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency($page['frequency']) ->setPriority($page['priority']) ); } // Price range pages $priceRanges = [ 'under-80000' => 'Under 80,000', '1-lakh' => '1 Lakh', '1-5-lakh' => '1.5 Lakh', '2-lakh' => '2 Lakh', '3-lakh' => '3 Lakh', '4-lakh' => '4 Lakh', '5-lakh' => '5 Lakh', 'above-5-lakh' => 'Above 5 Lakh' ]; foreach ($priceRanges as $slug => $name) { $sitemap->add( Url::create($this->getSitemapUrl("/bikes/price/{$slug}")) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } // Displacement pages $displacements = ['100cc', '125cc', '150cc', '160cc', '200cc', '250cc', '300cc', '400cc', '500cc', '600cc', '1000cc']; foreach ($displacements as $displacement) { $sitemap->add( Url::create($this->getSitemapUrl("/bikes/displacement/{$displacement}")) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate bike types sitemap */ public function bikeTypes() { $sitemap = Sitemap::create(); $bikeTypes = BikeType::active() ->orderBy('updated_at', 'desc') ->get(); foreach ($bikeTypes as $bikeType) { $sitemap->add( Url::create($this->getSitemapUrl("/type/{$bikeType->slug}")) ->setLastModificationDate($bikeType->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate showrooms sitemap */ public function showrooms() { $sitemap = Sitemap::create(); $showrooms = Showroom::where('is_active', true) ->orderBy('updated_at', 'desc') ->get(); foreach ($showrooms as $showroom) { $sitemap->add( Url::create($this->getSitemapUrl("/showroom/{$showroom->slug}")) ->setLastModificationDate($showroom->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_MONTHLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate blog sitemap */ public function blogs() { $sitemap = Sitemap::create(); $blogs = Blog::published() ->orderBy('updated_at', 'desc') ->get(); foreach ($blogs as $blog) { $sitemap->add( Url::create($this->getSitemapUrl("/blog/{$blog->slug}")) ->setLastModificationDate($blog->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_MONTHLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate blog categories sitemap */ public function blogCategories() { $sitemap = Sitemap::create(); $blogCategories = BlogCategory::where('is_active', true) ->orderBy('updated_at', 'desc') ->get(); foreach ($blogCategories as $category) { $sitemap->add( Url::create($this->getSitemapUrl("/blog/category/{$category->slug}")) ->setLastModificationDate($category->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate comparisons sitemap */ public function comparisons() { $sitemap = Sitemap::create(); $comparisons = BikeComparison::where('is_published', true) ->with(['bike1', 'bike2']) ->orderBy('updated_at', 'desc') ->get(); foreach ($comparisons as $comparison) { $sitemap->add( Url::create($this->getSitemapUrl("/comparison/{$comparison->bike1->slug}/vs/{$comparison->bike2->slug}")) ->setLastModificationDate($comparison->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } } ÿþ<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\Response; use Spatie\Sitemap\Sitemap; use Spatie\Sitemap\SitemapIndex; use Spatie\Sitemap\Tags\Url; use App\Models\Motorcycle; use App\Models\Brand; use App\Models\BikeType; use App\Models\Blog; use App\Models\BlogCategory; use App\Models\Showroom; use App\Models\BikeComparison; use Carbon\Carbon; class SitemapController extends Controller { /** * Get the production URL for sitemap generation */ private function getSitemapUrl($path = '') { $baseUrl = 'https://www.bikersbuddy.com'; return $baseUrl . $path; } /** * Generate sitemap index (main index showing all sitemap files) */ public function index() { // Clear any output buffer to prevent XML declaration errors if (ob_get_level()) { ob_clean(); } $sitemapIndex = SitemapIndex::create(); // Add all sitemap files with their last modification dates // Brands sitemap if (Brand::active()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/brands.xml'), Brand::active()->latest('updated_at')->first()->updated_at); } // Motorcycles sitemap if (Motorcycle::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/motorcycle.xml'), Motorcycle::published()->latest('updated_at')->first()->updated_at); } // Specifications sitemap if (Motorcycle::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/specifications.xml'), Motorcycle::published()->latest('updated_at')->first()->updated_at); } // Pages sitemap $sitemapIndex->add($this->getSitemapUrl('/pages.xml'), Carbon::now()); // Bike types sitemap if (BikeType::active()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/bike-type.xml'), BikeType::active()->latest('updated_at')->first()->updated_at); } // Showrooms sitemap if (Showroom::where('is_active', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/showroom.xml'), Showroom::where('is_active', true)->latest('updated_at')->first()->updated_at); } // Blog sitemap if (Blog::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/blog.xml'), Blog::published()->latest('updated_at')->first()->updated_at); } // Blog categories sitemap if (BlogCategory::where('is_active', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/blog-category.xml'), BlogCategory::where('is_active', true)->latest('updated_at')->first()->updated_at); } // Comparisons sitemap if (BikeComparison::where('is_published', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/comparsion.xml'), BikeComparison::where('is_published', true)->latest('updated_at')->first()->updated_at); } return response($sitemapIndex->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate brands sitemap */ public function brands() { $sitemap = Sitemap::create(); $brands = Brand::active() ->orderBy('updated_at', 'desc') ->get(); foreach ($brands as $brand) { $sitemap->add( Url::create($this->getSitemapUrl("/brand/{$brand->slug}")) ->setLastModificationDate($brand->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.8) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate motorcycles sitemap */ public function motorcycles() { $sitemap = Sitemap::create(); $motorcycles = Motorcycle::published() ->with('brand') ->orderBy('updated_at', 'desc') ->get(); foreach ($motorcycles as $motorcycle) { $sitemap->add( Url::create($this->getSitemapUrl("/motorcycle/{$motorcycle->slug}")) ->setLastModificationDate($motorcycle->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.9) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate specifications sitemap */ public function specifications() { // Complete bypass of Laravel response system try { // Clean all output buffers aggressively while (ob_get_level()) { ob_end_clean(); } // Disable all error output error_reporting(0); ini_set('display_errors', 0); ini_set('log_errors', 0); // Disable session writes to prevent session cookies if (session_status() === PHP_SESSION_ACTIVE) { session_write_close(); } // Get motorcycles data $motorcycles = Motorcycle::published() ->select('slug', 'updated_at') ->orderBy('updated_at', 'desc') ->get(); // Generate XML manually to avoid any library interference $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n"; foreach ($motorcycles as $motorcycle) { $lastmod = $motorcycle->updated_at->toAtomString(); $xml .= ' <url>' . "\n"; $xml .= ' <loc>https://www.bikersbuddy.com/reviews/' . $motorcycle->slug . '/specifications</loc>' . "\n"; $xml .= ' <lastmod>' . $lastmod . '</lastmod>' . "\n"; $xml .= ' <changefreq>weekly</changefreq>' . "\n"; $xml .= ' <priority>0.8</priority>' . "\n"; $xml .= ' </url>' . "\n"; } $xml .= '</urlset>'; // Send headers manually header('Content-Type: application/xml; charset=UTF-8'); header('Cache-Control: public, max-age=3600'); header('X-Content-Type-Options: nosniff'); // Output and terminate completely echo $xml; exit; } catch (\Exception $e) { // Emergency fallback while (ob_get_level()) { ob_end_clean(); } header('Content-Type: application/xml; charset=UTF-8'); echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>'; exit; } } /** * Generate pages sitemap */ public function pages() { $sitemap = Sitemap::create(); // Homepage $sitemap->add( Url::create($this->getSitemapUrl('/')) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_DAILY) ->setPriority(1.0) ); // Static pages $staticPages = [ ['url' => '/brands', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/new-bikes', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/comparison', 'priority' => 0.7, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/showrooms', 'priority' => 0.7, 'frequency' => Url::CHANGE_FREQUENCY_MONTHLY], ['url' => '/blog', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_DAILY], ['url' => '/bike-price-in-bangladesh', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ]; foreach ($staticPages as $page) { $sitemap->add( Url::create($this->getSitemapUrl($page['url'])) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency($page['frequency']) ->setPriority($page['priority']) ); } // Price range pages $priceRanges = [ 'under-80000' => 'Under 80,000', '1-lakh' => '1 Lakh', '1-5-lakh' => '1.5 Lakh', '2-lakh' => '2 Lakh', '3-lakh' => '3 Lakh', '4-lakh' => '4 Lakh', '5-lakh' => '5 Lakh', 'above-5-lakh' => 'Above 5 Lakh' ]; foreach ($priceRanges as $slug => $name) { $sitemap->add( Url::create($this->getSitemapUrl("/bikes/price/{$slug}")) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } // Displacement pages $displacements = ['100cc', '125cc', '150cc', '160cc', '200cc', '250cc', '300cc', '400cc', '500cc', '600cc', '1000cc']; foreach ($displacements as $displacement) { $sitemap->add( Url::create($this->getSitemapUrl("/bikes/displacement/{$displacement}")) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate bike types sitemap */ public function bikeTypes() { $sitemap = Sitemap::create(); $bikeTypes = BikeType::active() ->orderBy('updated_at', 'desc') ->get(); foreach ($bikeTypes as $bikeType) { $sitemap->add( Url::create($this->getSitemapUrl("/type/{$bikeType->slug}")) ->setLastModificationDate($bikeType->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate showrooms sitemap */ public function showrooms() { $sitemap = Sitemap::create(); $showrooms = Showroom::where('is_active', true) ->orderBy('updated_at', 'desc') ->get(); foreach ($showrooms as $showroom) { $sitemap->add( Url::create($this->getSitemapUrl("/showroom/{$showroom->slug}")) ->setLastModificationDate($showroom->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_MONTHLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate blog sitemap */ public function blogs() { $sitemap = Sitemap::create(); $blogs = Blog::published() ->orderBy('updated_at', 'desc') ->get(); foreach ($blogs as $blog) { $sitemap->add( Url::create($this->getSitemapUrl("/blog/{$blog->slug}")) ->setLastModificationDate($blog->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_MONTHLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate blog categories sitemap */ public function blogCategories() { $sitemap = Sitemap::create(); $blogCategories = BlogCategory::where('is_active', true) ->orderBy('updated_at', 'desc') ->get(); foreach ($blogCategories as $category) { $sitemap->add( Url::create($this->getSitemapUrl("/blog/category/{$category->slug}")) ->setLastModificationDate($category->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate comparisons sitemap */ public function comparisons() { $sitemap = Sitemap::create(); $comparisons = BikeComparison::where('is_published', true) ->with(['bike1', 'bike2']) ->orderBy('updated_at', 'desc') ->get(); foreach ($comparisons as $comparison) { $sitemap->add( Url::create($this->getSitemapUrl("/comparison/{$comparison->bike1->slug}/vs/{$comparison->bike2->slug}")) ->setLastModificationDate($comparison->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } } ÿþ<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\Response; use Spatie\Sitemap\Sitemap; use Spatie\Sitemap\SitemapIndex; use Spatie\Sitemap\Tags\Url; use App\Models\Motorcycle; use App\Models\Brand; use App\Models\BikeType; use App\Models\Blog; use App\Models\BlogCategory; use App\Models\Showroom; use App\Models\BikeComparison; use Carbon\Carbon; class SitemapController extends Controller { /** * Get the production URL for sitemap generation */ private function getSitemapUrl($path = '') { $baseUrl = 'https://www.bikersbuddy.com'; return $baseUrl . $path; } /** * Generate sitemap index (main index showing all sitemap files) */ public function index() { // Clear any output buffer to prevent XML declaration errors if (ob_get_level()) { ob_clean(); } $sitemapIndex = SitemapIndex::create(); // Add all sitemap files with their last modification dates // Brands sitemap if (Brand::active()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/brands.xml'), Brand::active()->latest('updated_at')->first()->updated_at); } // Motorcycles sitemap if (Motorcycle::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/motorcycle.xml'), Motorcycle::published()->latest('updated_at')->first()->updated_at); } // Specifications sitemap if (Motorcycle::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/specifications.xml'), Motorcycle::published()->latest('updated_at')->first()->updated_at); } // Pages sitemap $sitemapIndex->add($this->getSitemapUrl('/pages.xml'), Carbon::now()); // Bike types sitemap if (BikeType::active()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/bike-type.xml'), BikeType::active()->latest('updated_at')->first()->updated_at); } // Showrooms sitemap if (Showroom::where('is_active', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/showroom.xml'), Showroom::where('is_active', true)->latest('updated_at')->first()->updated_at); } // Blog sitemap if (Blog::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/blog.xml'), Blog::published()->latest('updated_at')->first()->updated_at); } // Blog categories sitemap if (BlogCategory::where('is_active', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/blog-category.xml'), BlogCategory::where('is_active', true)->latest('updated_at')->first()->updated_at); } // Comparisons sitemap if (BikeComparison::where('is_published', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/comparsion.xml'), BikeComparison::where('is_published', true)->latest('updated_at')->first()->updated_at); } return response($sitemapIndex->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate brands sitemap */ public function brands() { $sitemap = Sitemap::create(); $brands = Brand::active() ->orderBy('updated_at', 'desc') ->get(); foreach ($brands as $brand) { $sitemap->add( Url::create($this->getSitemapUrl("/brand/{$brand->slug}")) ->setLastModificationDate($brand->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.8) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate motorcycles sitemap */ public function motorcycles() { $sitemap = Sitemap::create(); $motorcycles = Motorcycle::published() ->with('brand') ->orderBy('updated_at', 'desc') ->get(); foreach ($motorcycles as $motorcycle) { $sitemap->add( Url::create($this->getSitemapUrl("/motorcycle/{$motorcycle->slug}")) ->setLastModificationDate($motorcycle->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.9) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate specifications sitemap */ public function specifications() { // Complete bypass of Laravel response system try { // Clean all output buffers aggressively while (ob_get_level()) { ob_end_clean(); } // Disable all error output error_reporting(0); ini_set('display_errors', 0); ini_set('log_errors', 0); // Disable session writes to prevent session cookies if (session_status() === PHP_SESSION_ACTIVE) { session_write_close(); } // Get motorcycles data $motorcycles = Motorcycle::published() ->select('slug', 'updated_at') ->orderBy('updated_at', 'desc') ->get(); // Generate XML manually to avoid any library interference $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n"; foreach ($motorcycles as $motorcycle) { $lastmod = $motorcycle->updated_at->toAtomString(); $xml .= ' <url>' . "\n"; $xml .= ' <loc>https://www.bikersbuddy.com/reviews/' . $motorcycle->slug . '/specifications</loc>' . "\n"; $xml .= ' <lastmod>' . $lastmod . '</lastmod>' . "\n"; $xml .= ' <changefreq>weekly</changefreq>' . "\n"; $xml .= ' <priority>0.8</priority>' . "\n"; $xml .= ' </url>' . "\n"; } $xml .= '</urlset>'; // Send headers manually header('Content-Type: application/xml; charset=UTF-8'); header('Cache-Control: public, max-age=3600'); header('X-Content-Type-Options: nosniff'); // Output and terminate completely echo $xml; exit; } catch (\Exception $e) { // Emergency fallback while (ob_get_level()) { ob_end_clean(); } header('Content-Type: application/xml; charset=UTF-8'); echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>'; exit; } } /** * Generate pages sitemap */ public function pages() { $sitemap = Sitemap::create(); // Homepage $sitemap->add( Url::create($this->getSitemapUrl('/')) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_DAILY) ->setPriority(1.0) ); // Static pages $staticPages = [ ['url' => '/brands', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/new-bikes', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/comparison', 'priority' => 0.7, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/showrooms', 'priority' => 0.7, 'frequency' => Url::CHANGE_FREQUENCY_MONTHLY], ['url' => '/blog', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_DAILY], ['url' => '/bike-price-in-bangladesh', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ]; foreach ($staticPages as $page) { $sitemap->add( Url::create($this->getSitemapUrl($page['url'])) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency($page['frequency']) ->setPriority($page['priority']) ); } // Price range pages $priceRanges = [ 'under-80000' => 'Under 80,000', '1-lakh' => '1 Lakh', '1-5-lakh' => '1.5 Lakh', '2-lakh' => '2 Lakh', '3-lakh' => '3 Lakh', '4-lakh' => '4 Lakh', '5-lakh' => '5 Lakh', 'above-5-lakh' => 'Above 5 Lakh' ]; foreach ($priceRanges as $slug => $name) { $sitemap->add( Url::create($this->getSitemapUrl("/bikes/price/{$slug}")) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } // Displacement pages $displacements = ['100cc', '125cc', '150cc', '160cc', '200cc', '250cc', '300cc', '400cc', '500cc', '600cc', '1000cc']; foreach ($displacements as $displacement) { $sitemap->add( Url::create($this->getSitemapUrl("/bikes/displacement/{$displacement}")) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate bike types sitemap */ public function bikeTypes() { $sitemap = Sitemap::create(); $bikeTypes = BikeType::active() ->orderBy('updated_at', 'desc') ->get(); foreach ($bikeTypes as $bikeType) { $sitemap->add( Url::create($this->getSitemapUrl("/type/{$bikeType->slug}")) ->setLastModificationDate($bikeType->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate showrooms sitemap */ public function showrooms() { $sitemap = Sitemap::create(); $showrooms = Showroom::where('is_active', true) ->orderBy('updated_at', 'desc') ->get(); foreach ($showrooms as $showroom) { $sitemap->add( Url::create($this->getSitemapUrl("/showroom/{$showroom->slug}")) ->setLastModificationDate($showroom->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_MONTHLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate blog sitemap */ public function blogs() { $sitemap = Sitemap::create(); $blogs = Blog::published() ->orderBy('updated_at', 'desc') ->get(); foreach ($blogs as $blog) { $sitemap->add( Url::create($this->getSitemapUrl("/blog/{$blog->slug}")) ->setLastModificationDate($blog->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_MONTHLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate blog categories sitemap */ public function blogCategories() { $sitemap = Sitemap::create(); $blogCategories = BlogCategory::where('is_active', true) ->orderBy('updated_at', 'desc') ->get(); foreach ($blogCategories as $category) { $sitemap->add( Url::create($this->getSitemapUrl("/blog/category/{$category->slug}")) ->setLastModificationDate($category->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate comparisons sitemap */ public function comparisons() { $sitemap = Sitemap::create(); $comparisons = BikeComparison::where('is_published', true) ->with(['bike1', 'bike2']) ->orderBy('updated_at', 'desc') ->get(); foreach ($comparisons as $comparison) { $sitemap->add( Url::create($this->getSitemapUrl("/comparison/{$comparison->bike1->slug}/vs/{$comparison->bike2->slug}")) ->setLastModificationDate($comparison->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } } ÿþ<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\Response; use Spatie\Sitemap\Sitemap; use Spatie\Sitemap\SitemapIndex; use Spatie\Sitemap\Tags\Url; use App\Models\Motorcycle; use App\Models\Brand; use App\Models\BikeType; use App\Models\Blog; use App\Models\BlogCategory; use App\Models\Showroom; use App\Models\BikeComparison; use Carbon\Carbon; class SitemapController extends Controller { /** * Get the production URL for sitemap generation */ private function getSitemapUrl($path = '') { $baseUrl = 'https://www.bikersbuddy.com'; return $baseUrl . $path; } /** * Generate sitemap index (main index showing all sitemap files) */ public function index() { // Clear any output buffer to prevent XML declaration errors if (ob_get_level()) { ob_clean(); } $sitemapIndex = SitemapIndex::create(); // Add all sitemap files with their last modification dates // Brands sitemap if (Brand::active()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/brands.xml'), Brand::active()->latest('updated_at')->first()->updated_at); } // Motorcycles sitemap if (Motorcycle::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/motorcycle.xml'), Motorcycle::published()->latest('updated_at')->first()->updated_at); } // Specifications sitemap if (Motorcycle::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/specifications.xml'), Motorcycle::published()->latest('updated_at')->first()->updated_at); } // Pages sitemap $sitemapIndex->add($this->getSitemapUrl('/pages.xml'), Carbon::now()); // Bike types sitemap if (BikeType::active()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/bike-type.xml'), BikeType::active()->latest('updated_at')->first()->updated_at); } // Showrooms sitemap if (Showroom::where('is_active', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/showroom.xml'), Showroom::where('is_active', true)->latest('updated_at')->first()->updated_at); } // Blog sitemap if (Blog::published()->exists()) { $sitemapIndex->add($this->getSitemapUrl('/blog.xml'), Blog::published()->latest('updated_at')->first()->updated_at); } // Blog categories sitemap if (BlogCategory::where('is_active', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/blog-category.xml'), BlogCategory::where('is_active', true)->latest('updated_at')->first()->updated_at); } // Comparisons sitemap if (BikeComparison::where('is_published', true)->exists()) { $sitemapIndex->add($this->getSitemapUrl('/comparsion.xml'), BikeComparison::where('is_published', true)->latest('updated_at')->first()->updated_at); } return response($sitemapIndex->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate brands sitemap */ public function brands() { $sitemap = Sitemap::create(); $brands = Brand::active() ->orderBy('updated_at', 'desc') ->get(); foreach ($brands as $brand) { $sitemap->add( Url::create($this->getSitemapUrl("/brand/{$brand->slug}")) ->setLastModificationDate($brand->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.8) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate motorcycles sitemap */ public function motorcycles() { $sitemap = Sitemap::create(); $motorcycles = Motorcycle::published() ->with('brand') ->orderBy('updated_at', 'desc') ->get(); foreach ($motorcycles as $motorcycle) { $sitemap->add( Url::create($this->getSitemapUrl("/motorcycle/{$motorcycle->slug}")) ->setLastModificationDate($motorcycle->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.9) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate specifications sitemap */ public function specifications() { // Complete bypass of Laravel response system try { // Clean all output buffers aggressively while (ob_get_level()) { ob_end_clean(); } // Disable all error output error_reporting(0); ini_set('display_errors', 0); ini_set('log_errors', 0); // Disable session writes to prevent session cookies if (session_status() === PHP_SESSION_ACTIVE) { session_write_close(); } // Get motorcycles data $motorcycles = Motorcycle::published() ->select('slug', 'updated_at') ->orderBy('updated_at', 'desc') ->get(); // Generate XML manually to avoid any library interference $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n"; foreach ($motorcycles as $motorcycle) { $lastmod = $motorcycle->updated_at->toAtomString(); $xml .= ' <url>' . "\n"; $xml .= ' <loc>https://www.bikersbuddy.com/reviews/' . $motorcycle->slug . '/specifications</loc>' . "\n"; $xml .= ' <lastmod>' . $lastmod . '</lastmod>' . "\n"; $xml .= ' <changefreq>weekly</changefreq>' . "\n"; $xml .= ' <priority>0.8</priority>' . "\n"; $xml .= ' </url>' . "\n"; } $xml .= '</urlset>'; // Send headers manually header('Content-Type: application/xml; charset=UTF-8'); header('Cache-Control: public, max-age=3600'); header('X-Content-Type-Options: nosniff'); // Output and terminate completely echo $xml; exit; } catch (\Exception $e) { // Emergency fallback while (ob_get_level()) { ob_end_clean(); } header('Content-Type: application/xml; charset=UTF-8'); echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>'; exit; } } /** * Generate pages sitemap */ public function pages() { $sitemap = Sitemap::create(); // Homepage $sitemap->add( Url::create($this->getSitemapUrl('/')) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_DAILY) ->setPriority(1.0) ); // Static pages $staticPages = [ ['url' => '/brands', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/new-bikes', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/comparison', 'priority' => 0.7, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ['url' => '/showrooms', 'priority' => 0.7, 'frequency' => Url::CHANGE_FREQUENCY_MONTHLY], ['url' => '/blog', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_DAILY], ['url' => '/bike-price-in-bangladesh', 'priority' => 0.8, 'frequency' => Url::CHANGE_FREQUENCY_WEEKLY], ]; foreach ($staticPages as $page) { $sitemap->add( Url::create($this->getSitemapUrl($page['url'])) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency($page['frequency']) ->setPriority($page['priority']) ); } // Price range pages $priceRanges = [ 'under-80000' => 'Under 80,000', '1-lakh' => '1 Lakh', '1-5-lakh' => '1.5 Lakh', '2-lakh' => '2 Lakh', '3-lakh' => '3 Lakh', '4-lakh' => '4 Lakh', '5-lakh' => '5 Lakh', 'above-5-lakh' => 'Above 5 Lakh' ]; foreach ($priceRanges as $slug => $name) { $sitemap->add( Url::create($this->getSitemapUrl("/bikes/price/{$slug}")) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } // Displacement pages $displacements = ['100cc', '125cc', '150cc', '160cc', '200cc', '250cc', '300cc', '400cc', '500cc', '600cc', '1000cc']; foreach ($displacements as $displacement) { $sitemap->add( Url::create($this->getSitemapUrl("/bikes/displacement/{$displacement}")) ->setLastModificationDate(Carbon::now()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate bike types sitemap */ public function bikeTypes() { $sitemap = Sitemap::create(); $bikeTypes = BikeType::active() ->orderBy('updated_at', 'desc') ->get(); foreach ($bikeTypes as $bikeType) { $sitemap->add( Url::create($this->getSitemapUrl("/type/{$bikeType->slug}")) ->setLastModificationDate($bikeType->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate showrooms sitemap */ public function showrooms() { $sitemap = Sitemap::create(); $showrooms = Showroom::where('is_active', true) ->orderBy('updated_at', 'desc') ->get(); foreach ($showrooms as $showroom) { $sitemap->add( Url::create($this->getSitemapUrl("/showroom/{$showroom->slug}")) ->setLastModificationDate($showroom->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_MONTHLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate blog sitemap */ public function blogs() { $sitemap = Sitemap::create(); $blogs = Blog::published() ->orderBy('updated_at', 'desc') ->get(); foreach ($blogs as $blog) { $sitemap->add( Url::create($this->getSitemapUrl("/blog/{$blog->slug}")) ->setLastModificationDate($blog->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_MONTHLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate blog categories sitemap */ public function blogCategories() { $sitemap = Sitemap::create(); $blogCategories = BlogCategory::where('is_active', true) ->orderBy('updated_at', 'desc') ->get(); foreach ($blogCategories as $category) { $sitemap->add( Url::create($this->getSitemapUrl("/blog/category/{$category->slug}")) ->setLastModificationDate($category->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.6) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } /** * Generate comparisons sitemap */ public function comparisons() { $sitemap = Sitemap::create(); $comparisons = BikeComparison::where('is_published', true) ->with(['bike1', 'bike2']) ->orderBy('updated_at', 'desc') ->get(); foreach ($comparisons as $comparison) { $sitemap->add( Url::create($this->getSitemapUrl("/comparison/{$comparison->bike1->slug}/vs/{$comparison->bike2->slug}")) ->setLastModificationDate($comparison->updated_at) ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY) ->setPriority(0.7) ); } return response($sitemap->render(), 200, [ 'Content-Type' => 'application/xml', 'Cache-Control' => 'public, max-age=3600' ]); } } Server Error
500
Server Error