]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/SitemapXmlController.php
basic map pins
[alttp.git] / app / Http / Controllers / SitemapXmlController.php
1 <?php
2
3 namespace App\Http\Controllers;
4
5 use App\Models\SitemapUrl;
6 use App\Models\Technique;
7 use App\Models\Tournament;
8 use Illuminate\Http\Request;
9
10 class SitemapXmlController extends Controller
11 {
12
13         public function index() {
14                 $urls = [];
15
16                 foreach (Tournament::all() as $tournament) {
17                         $url = new SitemapUrl();
18                         $url->path = '/tournaments/'.$tournament->id;
19                         $url->lastmod = $tournament->updated_at ? $tournament->updated_at : ($tournament->created_at ? $tournament->created_at : now());
20                         $url->changefreq = $tournament->locked ? 'never' : 'daily';
21                         $url->priority = $tournament->locked ? 0.5 : 1.0;
22                         $urls[] = $url;
23                 }
24
25                 $url = new SitemapUrl();
26                 $url->path = '/tech';
27                 $url->lastmod = Technique::where('type', '=', 'tech')->where('index', true)->latest()->first()->created_at;
28                 $url->changefreq = 'monthly';
29                 $url->priority = 0.5;
30                 $urls[] = $url;
31
32                 foreach (Technique::where('type', '=', 'tech')->where('index', true)->get() as $tech) {
33                         $url = new SitemapUrl();
34                         $url->path = '/tech/'.rawurlencode($tech->name);
35                         $url->lastmod = $tech->updated_at ? $tech->updated_at : ($tech->created_at ? $tech->created_at : now());
36                         $url->changefreq = 'never';
37                         $url->priority = $tech->priority;
38                         $urls[] = $url;
39                 }
40
41                 return response()->view('sitemap', [
42                         'urls' => $urls,
43                 ])->header('Content-Type', 'text/xml');
44         }
45
46 }