1
|
|
|
<?php |
2
|
|
|
namespace Xetaravel\Http\Controllers; |
3
|
|
|
|
4
|
|
|
use Illuminate\Contracts\View\View as ViewView; |
5
|
|
|
use Illuminate\Contracts\View\Factory; |
6
|
|
|
use Illuminate\Contracts\Container\BindingResolutionException; |
7
|
|
|
use Illuminate\Http\RedirectResponse; |
8
|
|
|
use Illuminate\Http\Request ; |
9
|
|
|
use Illuminate\Support\Facades\App; |
10
|
|
|
use Illuminate\Support\Facades\Auth; |
11
|
|
|
use Illuminate\Support\Facades\Mail; |
12
|
|
|
use Illuminate\Support\Facades\Validator; |
13
|
|
|
use Illuminate\View\View; |
14
|
|
|
use Xetaravel\Models\Article; |
15
|
|
|
use Xetaravel\Models\Comment; |
16
|
|
|
use Xetaravel\Mail\Contact; |
17
|
|
|
|
18
|
|
|
class PageController extends Controller |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Show the home page. |
22
|
|
|
* |
23
|
|
|
* @return \Illuminate\Http\Response |
24
|
|
|
*/ |
25
|
|
|
public function index() |
26
|
|
|
{ |
27
|
|
|
$article = Article::with('category', 'user') |
28
|
|
|
->latest() |
29
|
|
|
->first(); |
30
|
|
|
|
31
|
|
|
return view('page.index', ['article' => $article]); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Display the terms page. |
36
|
|
|
* |
37
|
|
|
* @return \Illuminate\Http\Response |
38
|
|
|
*/ |
39
|
|
|
public function terms() |
40
|
|
|
{ |
41
|
|
|
$this->breadcrumbs->addCrumb('Terms', route('page.terms')); |
42
|
|
|
|
43
|
|
|
return view('page.terms', ['breadcrumbs' => $this->breadcrumbs]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Display the contact page. |
48
|
|
|
* |
49
|
|
|
* @return \Illuminate\View\View |
50
|
|
|
*/ |
51
|
|
|
public function showContact(): View |
52
|
|
|
{ |
53
|
|
|
$this->breadcrumbs->addCrumb('Contact', route('page.contact')); |
54
|
|
|
|
55
|
|
|
return view('page.contact', ['breadcrumbs' => $this->breadcrumbs]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Send an E-mail to . |
60
|
|
|
* |
61
|
|
|
* @param \Illuminate\Http\Request $request The current request. |
62
|
|
|
* |
63
|
|
|
* @return \Illuminate\Http\RedirectResponse |
64
|
|
|
*/ |
65
|
|
|
public function contact(Request $request): RedirectResponse |
66
|
|
|
{ |
67
|
|
|
$rules = [ |
68
|
|
|
'name' => 'required|min:4|max:30', |
69
|
|
|
'email' => 'required|email|max:50', |
70
|
|
|
'message' => 'required|min:10', |
71
|
|
|
]; |
72
|
|
|
|
73
|
|
|
// Bipass the captcha for the unit testing. |
74
|
|
|
if (App::environment() !== 'testing') { |
75
|
|
|
$rules = array_merge($rules, ['g-recaptcha-response' => 'required|captcha']); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
Validator::make($request->all(), $rules)->validate(); |
79
|
|
|
|
80
|
|
|
$details = [ |
81
|
|
|
'name' => $request->get('name'), |
82
|
|
|
'email' => $request->get('email'), |
83
|
|
|
'subject' => $request->get('subject'), |
84
|
|
|
'message' => $request->get('message'), |
85
|
|
|
'ip' => $request->ip() |
86
|
|
|
]; |
87
|
|
|
|
88
|
|
|
Mail::to(config('xetaravel.site.contact_email'))->send(new Contact($details)); |
89
|
|
|
|
90
|
|
|
return redirect() |
91
|
|
|
->route('page.contact') |
92
|
|
|
->with('success', 'Thanks for contacting me ! I will answer you as fast as I can !'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Display the banished page. |
97
|
|
|
* |
98
|
|
|
* @return \Illuminate\Http\Response |
99
|
|
|
*/ |
100
|
|
|
public function banished() |
101
|
|
|
{ |
102
|
|
|
if (!Auth::user()->hasRole('banished')) { |
103
|
|
|
return redirect() |
104
|
|
|
->route('page.index'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return view('page.banished'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Display my custom page. |
112
|
|
|
* |
113
|
|
|
* @return \Illuminate\Http\Response |
114
|
|
|
*/ |
115
|
|
|
public function aboutme() |
116
|
|
|
{ |
117
|
|
|
return view('page.aboutme'); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|