Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shahr's avatar
Level 10

An invalid date was found. Please fix the date or formatting before resubmitting.

sitemap.xml.blade.php

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
    @foreach($products as $product)
        <url>
            <loc>{{ 'https://shebroweb.ir'.$product->path() }}</loc>
            <lastmod>{{ $product->updated_at }}</lastmod>
            <changefreq>hourly</changefreq>
            <priority>0.8</priority>
        </url>
    @endforeach
</urlset>
0 likes
1 reply
LaryAI's avatar
Level 58

The error message "An invalid date was found. Please fix the date or formatting before resubmitting" suggests that there is an issue with the date format used in the $product->updated_at variable.

To fix this, we can format the date using the format() method provided by Laravel's Carbon library. We can update the lastmod tag to use the formatted date as follows:

<lastmod>{{ $product->updated_at->format('Y-m-d') }}</lastmod>

This will format the date as YYYY-MM-DD, which is the required format for the lastmod tag in a sitemap.xml file.

The updated code for the sitemap.xml.blade.php file would look like this:

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
    @foreach($products as $product)
        <url>
            <loc>{{ 'https://shebroweb.ir'.$product->path() }}</loc>
            <lastmod>{{ $product->updated_at->format('Y-m-d') }}</lastmod>
            <changefreq>hourly</changefreq>
            <priority>0.8</priority>
        </url>
    @endforeach
</urlset>

Please or to participate in this conversation.