1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Post; |
6
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Models\Event; |
7
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Models\Teacher; |
8
|
|
|
use DavideCasiraghi\LaravelQuickMenus\Models\MenuItem; |
9
|
|
|
use Illuminate\Support\Facades\DB; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Created using this tutorial: https://laravel-news.com/laravel-sitemap. |
13
|
|
|
**/ |
14
|
|
|
class SitemapController extends Controller |
15
|
|
|
{ |
16
|
|
|
/***************************************************************************/ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Display a listing of the resource. |
20
|
|
|
* |
21
|
|
|
* @return \Illuminate\Http\Response |
22
|
|
|
*/ |
23
|
|
|
public function index() |
24
|
|
|
{ |
25
|
|
|
/*$post = Post::orderBy('updated_at', 'desc')->first(); |
26
|
|
|
$event = Event::orderBy('updated_at', 'desc')->first(); |
27
|
|
|
$teacher = Teacher::orderBy('updated_at', 'desc')->first();*/ |
28
|
|
|
|
29
|
|
|
$menuItems = MenuItem::where('access', 1)->get(); |
30
|
|
|
|
31
|
|
|
return response()->view('sitemap.index', [ |
32
|
|
|
'menuItems' => $menuItems, |
33
|
|
|
])->header('Content-Type', 'text/xml'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/***************************************************************************/ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Generate the posts XML sitemap. |
40
|
|
|
* |
41
|
|
|
* @return \Illuminate\Http\Response |
42
|
|
|
*/ |
43
|
|
|
public function posts() |
44
|
|
|
{ |
45
|
|
|
//$posts = Post::where('category_id', 6)->get(); |
46
|
|
|
|
47
|
|
|
$posts = DB::table('posts') |
48
|
|
|
->join('post_translations', 'posts.id', '=', 'post_translations.post_id') |
49
|
|
|
->select('posts.*', 'post_translations.locale', 'post_translations.slug')->get(); |
50
|
|
|
|
51
|
|
|
//dd($posts); |
52
|
|
|
return response()->view('sitemap.posts', [ |
53
|
|
|
'posts' => $posts, |
54
|
|
|
])->header('Content-Type', 'text/xml'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/***************************************************************************/ |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Generate the events XML sitemap |
61
|
|
|
* every event show the link to the closest repetition related to today. |
62
|
|
|
* |
63
|
|
|
* @return \Illuminate\Http\Response |
64
|
|
|
*/ |
65
|
|
|
public function events() |
66
|
|
|
{ |
67
|
|
|
// Retrieve all the active events |
68
|
|
|
$filters = []; |
69
|
|
|
$filters['keywords'] = $filters['category'] = $filters['country'] = $filters['region'] = $filters['city'] = $filters['continent'] = $filters['teacher'] = $filters['venue'] = $filters['startDate'] = $filters['endDate'] = null; |
70
|
|
|
$activeEvents = Event::getEvents($filters, 10000); |
71
|
|
|
|
72
|
|
|
return response()->view('sitemap.events', [ |
73
|
|
|
'events' => $activeEvents, |
74
|
|
|
])->header('Content-Type', 'text/xml'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/***************************************************************************/ |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Generate the teachers XML sitemap. |
81
|
|
|
* |
82
|
|
|
* @return \Illuminate\Http\Response |
83
|
|
|
*/ |
84
|
|
|
public function teachers() |
85
|
|
|
{ |
86
|
|
|
$teachers = Teacher::orderBy('updated_at', 'desc')->get(); |
87
|
|
|
|
88
|
|
|
return response()->view('sitemap.teachers', [ |
89
|
|
|
'teachers' => $teachers, |
90
|
|
|
])->header('Content-Type', 'text/xml'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/***************************************************************************/ |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Display the specified resource. |
97
|
|
|
* |
98
|
|
|
* @return \Illuminate\View\View |
99
|
|
|
*/ |
100
|
|
|
public function show() |
101
|
|
|
{ |
102
|
|
|
$sitemap = $this->generateSitemapXML(); |
|
|
|
|
103
|
|
|
|
104
|
|
|
return view('sitemap.show', ['sitemap' => $sitemap]); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/***************************************************************************/ |
108
|
|
|
} |
109
|
|
|
|