|
1
|
|
|
<?php |
|
2
|
|
|
namespace Xetaravel\Http\Controllers; |
|
3
|
|
|
|
|
4
|
|
|
use Illuminate\Http\RedirectResponse; |
|
5
|
|
|
use Illuminate\Http\Request ; |
|
6
|
|
|
use Illuminate\Support\Facades\Auth; |
|
7
|
|
|
use Illuminate\Support\Facades\Mail; |
|
8
|
|
|
use Illuminate\View\View; |
|
9
|
|
|
use Xetaravel\Models\Article; |
|
10
|
|
|
use Xetaravel\Models\Comment; |
|
11
|
|
|
use Xetaravel\Mail\Contact; |
|
12
|
|
|
|
|
13
|
|
|
class PageController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Show the home page. |
|
17
|
|
|
* |
|
18
|
|
|
* @return \Illuminate\Http\Response |
|
19
|
|
|
*/ |
|
20
|
|
|
public function index() |
|
21
|
|
|
{ |
|
22
|
|
|
$articles = Article::with('category', 'user') |
|
23
|
|
|
->latest() |
|
24
|
|
|
->limit(6) |
|
25
|
|
|
->get(); |
|
26
|
|
|
|
|
27
|
|
|
$comments = Comment::with('user') |
|
28
|
|
|
->whereHas('article', function ($query) { |
|
29
|
|
|
$query->where('is_display', true); |
|
30
|
|
|
}) |
|
31
|
|
|
->latest() |
|
32
|
|
|
->limit(4) |
|
33
|
|
|
->get(); |
|
34
|
|
|
|
|
35
|
|
|
return view('page.index', ['articles' => $articles, 'comments' => $comments]); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Display the terms page. |
|
40
|
|
|
* |
|
41
|
|
|
* @return \Illuminate\Http\Response |
|
42
|
|
|
*/ |
|
43
|
|
|
public function terms() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->breadcrumbs->addCrumb('Terms', route('page.terms')); |
|
46
|
|
|
|
|
47
|
|
|
return view('page.terms', ['breadcrumbs' => $this->breadcrumbs]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Display the contact page. |
|
52
|
|
|
* |
|
53
|
|
|
* @return \Illuminate\View\View |
|
54
|
|
|
*/ |
|
55
|
|
|
public function showContact(): View |
|
56
|
|
|
{ |
|
57
|
|
|
$this->breadcrumbs->addCrumb('Contact', route('page.contact')); |
|
58
|
|
|
|
|
59
|
|
|
return view('page.contact', ['breadcrumbs' => $this->breadcrumbs]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Send an E-mail to . |
|
64
|
|
|
* |
|
65
|
|
|
* @param \Illuminate\Http\Request $request The current request. |
|
66
|
|
|
* |
|
67
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
68
|
|
|
*/ |
|
69
|
|
|
public function contact(Request $request): RedirectResponse |
|
70
|
|
|
{ |
|
71
|
|
|
$details = [ |
|
72
|
|
|
'name' => $request->get('name'), |
|
73
|
|
|
'email' => $request->get('email'), |
|
74
|
|
|
'subject' => $request->get('subject'), |
|
75
|
|
|
'message' => $request->get('message'), |
|
76
|
|
|
'ip' => $request->ip() |
|
77
|
|
|
]; |
|
78
|
|
|
|
|
79
|
|
|
Mail::to(config('xetaravel.site.contact_email'))->send(new Contact($details)); |
|
80
|
|
|
|
|
81
|
|
|
return redirect() |
|
82
|
|
|
->route('page.contact') |
|
83
|
|
|
->with('success', 'Thanks for contacting me ! I will answer you as fast as I can !'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Display the banished page. |
|
88
|
|
|
* |
|
89
|
|
|
* @return \Illuminate\Http\Response |
|
90
|
|
|
*/ |
|
91
|
|
|
public function banished() |
|
92
|
|
|
{ |
|
93
|
|
|
if (!Auth::user()->hasRole('banished')) { |
|
94
|
|
|
return redirect() |
|
95
|
|
|
->route('page.index'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return view('page.banished'); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|