la_bloger/app/Http/Controllers/SitemapController.php

24 lines
666 B
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Channel;
use App\Models\Publication;
use Illuminate\Http\Response;
class SitemapController extends Controller
{
public function index(Channel $channel): Response
{
$publications = Publication::published()
->forChannel($channel)
->with('channel.prefixes')
->select(['id', 'post_id', 'slug', 'channel_id', 'published_at', 'updated_at'])
->latest('published_at')
->get();
return response()
->view('theme::sitemap', compact('publications', 'channel'))
->header('Content-Type', 'application/xml');
}
}