# Sitemap Generator
A comprehensive XML sitemap generator for your Laravel application that automatically includes your dynamic content (companies, venues, venue objects, products) and static pages.
## Features
- πΊοΈ **XML Sitemap Generation**: Generates standards-compliant XML sitemaps
- π **Dynamic Content**: Automatically includes active companies, venues, venue objects, and products
- π **Static Pages**: Configurable static pages with custom priorities and change frequencies
- ποΈ **Sitemap Index**: Automatically creates sitemap index for large sites
- β‘ **Caching**: Built-in caching for improved performance
- π **Queue Support**: Background job generation for large sites
- π **Search Engine Submission**: Automatic submission to Google and Bing
- βοΈ **Configurable**: Extensive configuration options
## Installation
The sitemap generator is already integrated into your application. Here's how to use it:
## Usage
### 1. Generate Sitemap via Command
```bash
# Generate sitemap
php artisan sitemap:generate
# Generate sitemap and submit to search engines
php artisan sitemap:generate --submit
# Generate sitemap with statistics
php artisan sitemap:generate --stats
```
### 2. Access Sitemap via URL
```
https://yourdomain.com/sitemap.xml
```
### 3. API Generation
```bash
# Generate via HTTP request
curl -X POST https://yourdomain.com/sitemap/generate
```
## Configuration
Edit `config/custom-sitemap.php` to customize your sitemap:
### Base URL
```php
'base_url' => env('SITEMAP_BASE_URL', config('app.url')),
```
### Static Pages
```php
'static_pages' => [
'/' => ['priority' => '1.0', 'changefreq' => 'daily'],
'/about' => ['priority' => '0.8', 'changefreq' => 'monthly'],
'/contact' => ['priority' => '0.7', 'changefreq' => 'monthly'],
// Add more pages as needed
],
```
### Include/Exclude Models
```php
'include_models' => [
'companies' => true,
'venues' => true,
'venue_objects' => true,
'products' => true,
],
```
## Automation
### 1. Schedule Automatic Generation
Add to `app/Console/Kernel.php`:
```php
protected function schedule(Schedule $schedule)
{
// Generate sitemap daily at 2 AM
$schedule->command('sitemap:generate')
->dailyAt('02:00')
->withoutOverlapping();
// Or use the job for better performance
$schedule->job(new \App\Jobs\GenerateSitemapJob())
->dailyAt('02:00')
->withoutOverlapping();
}
```
### 2. Auto-Submit to Search Engines
Set in your `.env` file:
```env
SITEMAP_AUTO_SUBMIT=true
```
## Sitemap Structure
### Single Sitemap
For smaller sites (< 50,000 URLs):
```
sitemap.xml
βββ Static pages
βββ Companies
βββ Venues
βββ Venue Objects
βββ Products
```
### Sitemap Index
For larger sites (> 50,000 URLs):
```
sitemap-index.xml
βββ static-pages.xml
βββ companies.xml
βββ venues.xml
βββ venue-objects.xml
βββ products.xml
```
## Priority Guidelines
- **1.0**: Homepage
- **0.9**: Main category pages (venues)
- **0.8**: Important pages (about, companies)
- **0.7**: Standard pages (products, contact)
- **0.6**: Less important pages (FAQ)
- **0.5**: Legal pages (terms, privacy)
## Change Frequency Guidelines
- **daily**: Homepage, main listing pages
- **weekly**: Product pages, company pages
- **monthly**: About page, contact page
- **yearly**: Terms, privacy policy
## SEO Best Practices
1. **Submit to Search Engines**: Use the `--submit` flag or set `SITEMAP_AUTO_SUBMIT=true`
2. **Update Regularly**: Schedule daily generation for dynamic content
3. **Monitor**: Check Google Search Console for sitemap errors
4. **Keep Under Limits**: Stay under 50,000 URLs and 50MB per sitemap
5. **Use Proper Priorities**: Set realistic priorities based on importance
## Troubleshooting
### Common Issues
1. **404 Error**: Ensure the sitemap file exists in `public/` directory
2. **Permission Error**: Check file permissions for `public/` directory
3. **Memory Error**: Use queue job for large sites
4. **Missing URLs**: Verify models have `slug` field and `is_active` column
### Debug Mode
Add to your route for debugging:
```php
Route::get('/sitemap-debug', function () {
$generator = new \App\Services\SitemapGenerator();
dd($generator->getStats());
});
```
## Performance Tips
1. **Enable Caching**: Default cache duration is 60 minutes
2. **Use Queue Jobs**: For sites with > 10,000 URLs
3. **Optimize Queries**: Add database indexes on `slug` and `is_active` columns
4. **CDN**: Serve sitemaps via CDN for faster access
## Monitoring
Monitor your sitemap in:
- Google Search Console
- Bing Webmaster Tools
- Yandex Webmaster
## Support
For issues or questions:
1. Check Laravel logs: `storage/logs/laravel.log`
2. Verify configuration in `config/custom-sitemap.php`
3. Test with the `--stats` flag for detailed information
## Security
- Sitemap files are publicly accessible
- No sensitive data is included
- File access is restricted to XML files only
- Directory traversal protection is implemented