3 namespace App\Http\Controllers;
5 use App\Models\Episode;
7 use App\Models\SitemapUrl;
8 use App\Models\Technique;
9 use App\Models\TechniqueMap;
10 use App\Models\Tournament;
11 use Illuminate\Http\Request;
13 class SitemapXmlController extends Controller
16 public function index() {
19 foreach (Tournament::all() as $tournament) {
20 $url = new SitemapUrl();
21 $url->path = '/tournaments/'.$tournament->id;
22 $url->lastmod = $tournament->updated_at ? $tournament->updated_at : ($tournament->created_at ? $tournament->created_at : now());
23 $url->changefreq = $tournament->locked ? 'never' : 'daily';
24 $url->priority = $tournament->locked ? 0.5 : 1.0;
28 foreach (['lw', 'dw', 'sp', 'uw', 'uw2'] as $map) {
29 $tech = TechniqueMap::where('map', '=', $map)->latest()->first();
30 $url = new SitemapUrl();
31 $url->path = '/map/'.$map;
33 $url->lastmod = $tech->created_at;
35 $url->changefreq = 'monthly';
40 $url = new SitemapUrl();
42 $url->lastmod = Technique::where('type', '=', 'tech')->where('index', true)->latest()->first()->created_at;
43 $url->changefreq = 'monthly';
47 foreach (Technique::where('type', '=', 'tech')->where('index', true)->get() as $tech) {
48 $url = new SitemapUrl();
49 $url->path = '/tech/'.rawurlencode($tech->name);
50 $url->lastmod = $tech->updated_at ? $tech->updated_at : ($tech->created_at ? $tech->created_at : now());
51 $url->changefreq = 'never';
52 $url->priority = $tech->priority;
56 $url = new SitemapUrl();
57 $url->path = '/schedule';
58 $url->lastmod = Episode::where('confirmed', true)->latest()->first()->created_at;
59 $url->changefreq = 'daily';
63 $url = new SitemapUrl();
64 $url->path = '/events';
65 $url->lastmod = Event::where('visible', true)->latest()->first()->created_at;
66 $url->changefreq = 'monthly';
70 foreach (Event::where('visible', true)->get() as $event) {
71 $url = new SitemapUrl();
72 $url->path = '/events/'.rawurlencode($event->name);
73 $url->lastmod = $event->updated_at ? $event->updated_at : ($event->created_at ? $event->created_at : now());
74 $url->changefreq = 'never';
79 return response()->view('sitemap', [
81 ])->header('Content-Type', 'text/xml');