Files
amare/app/Application/Queries/Marketing/GetSitemapEntries.php

60 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Application\Queries\Marketing;
use App\Models\PortfolioCase;
use App\Models\WeddingPackage;
use Illuminate\Support\Carbon;
final class GetSitemapEntries
{
/**
* @return list<array{loc: string, lastmod: string|null}>
*/
public function __invoke(): array
{
$entries = [
['loc' => route('home'), 'lastmod' => null],
['loc' => route('services.index'), 'lastmod' => null],
['loc' => route('portfolio.index'), 'lastmod' => null],
['loc' => route('about'), 'lastmod' => null],
['loc' => route('privacy'), 'lastmod' => null],
['loc' => route('contact'), 'lastmod' => null],
];
$cases = PortfolioCase::query()
->published()
->orderBy('sort_order')
->get(['slug', 'updated_at']);
foreach ($cases as $case) {
/** @var Carbon|null $updatedAt */
$updatedAt = $case->updated_at;
$entries[] = [
'loc' => route('portfolio.show', $case->slug),
'lastmod' => $updatedAt?->toAtomString(),
];
}
$packages = WeddingPackage::query()
->published()
->orderBy('sort_order')
->get(['slug', 'updated_at']);
foreach ($packages as $package) {
/** @var Carbon|null $updatedAt */
$updatedAt = $package->updated_at;
$entries[] = [
'loc' => route('packages.show', $package->slug),
'lastmod' => $updatedAt?->toAtomString(),
];
}
return $entries;
}
}