|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DavideCasiraghi\LaravelJumbotronImages\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Illuminate\Support\Facades\App; |
|
7
|
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
|
8
|
|
|
use DavideCasiraghi\LaravelJumbotronImages\Models\JumbotronImage; |
|
9
|
|
|
|
|
10
|
|
|
class JumbotronImageController |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Display the specified resource. |
|
14
|
|
|
* |
|
15
|
|
|
* @param \Illuminate\Http\Request $request |
|
16
|
|
|
* @return \Illuminate\Http\Response |
|
17
|
|
|
*/ |
|
18
|
|
|
public function index(Request $request) |
|
19
|
|
|
{ |
|
20
|
|
|
$searchKeywords = $request->input('keywords'); |
|
21
|
|
|
//$searchCategory = $request->input('category_id'); |
|
22
|
|
|
$countriesAvailableForTranslations = LaravelLocalization::getSupportedLocales(); |
|
23
|
|
|
|
|
24
|
|
|
if ($searchKeywords) { |
|
25
|
|
|
$jumbotronImages = JumbotronImage::orderBy('title') |
|
26
|
|
|
->where('title', 'like', '%'.$request->input('keywords').'%') |
|
27
|
|
|
->paginate(20); |
|
28
|
|
|
} else { |
|
29
|
|
|
$jumbotronImages = JumbotronImage::orderBy('title') |
|
30
|
|
|
->paginate(20); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
return view('laravel-jumbotron-images::jumbotronImages.index', compact('jumbotronImages')) |
|
34
|
|
|
->with('i', (request()->input('page', 1) - 1) * 20) |
|
35
|
|
|
->with('searchKeywords', $searchKeywords) |
|
36
|
|
|
->with('countriesAvailableForTranslations', $countriesAvailableForTranslations); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/***************************************************************************/ |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Show the form for creating a new resource. |
|
43
|
|
|
* |
|
44
|
|
|
* @return \Illuminate\Http\Response |
|
45
|
|
|
*/ |
|
46
|
|
|
public function create() |
|
47
|
|
|
{ |
|
48
|
|
|
return view('laravel-jumbotron-images::jumbotronImages.create'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/***************************************************************************/ |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Store a newly created resource in storage. |
|
55
|
|
|
* |
|
56
|
|
|
* @param \Illuminate\Http\Request $request |
|
57
|
|
|
* @return \Illuminate\Http\Response |
|
58
|
|
|
*/ |
|
59
|
|
|
public function store(Request $request) |
|
60
|
|
|
{ |
|
61
|
|
|
$jumbotronImage = new JumbotronImage(); |
|
62
|
|
|
$jumbotronImage->title = $request->get('title'); |
|
|
|
|
|
|
63
|
|
|
$jumbotronImage->body = $request->get('body'); |
|
|
|
|
|
|
64
|
|
|
$jumbotronImage->button_text = $request->get('button_text'); |
|
|
|
|
|
|
65
|
|
|
$jumbotronImage->image_file_name = $request->get('image_file_name'); |
|
66
|
|
|
$jumbotronImage->button_url = $request->get('button_url'); |
|
67
|
|
|
|
|
68
|
|
|
// Set the default language to edit the quote in English |
|
69
|
|
|
App::setLocale('en'); |
|
70
|
|
|
|
|
71
|
|
|
$this->saveOnDb($request, $jumbotronImage); |
|
72
|
|
|
|
|
73
|
|
|
return redirect()->route('jumbotron-images.index') |
|
74
|
|
|
->with('success', 'Jumbotron image added succesfully'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/***************************************************************************/ |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Display the specified resource. |
|
81
|
|
|
* |
|
82
|
|
|
* @param int $jumbotronImageId |
|
83
|
|
|
* @return \Illuminate\Http\Response |
|
84
|
|
|
*/ |
|
85
|
|
|
public function show($jumbotronImageId = null) |
|
86
|
|
|
{ |
|
87
|
|
|
$jumbotronImage = JumbotronImage::find($jumbotronImageId); |
|
88
|
|
|
|
|
89
|
|
|
return view('laravel-jumbotron-images::jumbotronImages.show', compact('jumbotronImage')); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/***************************************************************************/ |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Show the form for editing the specified resource. |
|
96
|
|
|
* |
|
97
|
|
|
* @param int $jumbotronImageId |
|
98
|
|
|
* @return \Illuminate\Http\Response |
|
99
|
|
|
*/ |
|
100
|
|
|
public function edit($jumbotronImageId = null) |
|
101
|
|
|
{ |
|
102
|
|
|
$jumbotronImage = JumbotronImage::find($jumbotronImageId); |
|
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
return view('laravel-jumbotron-images::jumbotronImages.edit', compact('quote')); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/***************************************************************************/ |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Update the specified resource in storage. |
|
111
|
|
|
* |
|
112
|
|
|
* @param \Illuminate\Http\Request $request |
|
113
|
|
|
* @param int $jumbotronImageId |
|
114
|
|
|
* @return \Illuminate\Http\Response |
|
115
|
|
|
*/ |
|
116
|
|
|
public function update(Request $request, $jumbotronImageId) |
|
117
|
|
|
{ |
|
118
|
|
|
$jumbotronImage = JumbotronImage::find($jumbotronImageId); |
|
119
|
|
|
|
|
120
|
|
|
// Set the default language to update the quote in English |
|
121
|
|
|
App::setLocale('en'); |
|
122
|
|
|
|
|
123
|
|
|
$this->saveOnDb($request, $jumbotronImage); |
|
124
|
|
|
|
|
125
|
|
|
return redirect()->route('jumbotron-images.index') |
|
126
|
|
|
->with('success', 'Jumbotron image updated succesfully'); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/***************************************************************************/ |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Remove the specified resource from storage. |
|
133
|
|
|
* |
|
134
|
|
|
* @param int $jumbotronImageId |
|
135
|
|
|
* @return \Illuminate\Http\Response |
|
136
|
|
|
*/ |
|
137
|
|
|
public function destroy($jumbotronImageId) |
|
138
|
|
|
{ |
|
139
|
|
|
$jumbotronImage = JumbotronImage::find($jumbotronImageId); |
|
140
|
|
|
$jumbotronImage->delete(); |
|
141
|
|
|
|
|
142
|
|
|
return redirect()->route('jumbotron-images.index') |
|
143
|
|
|
->with('success', 'Jumbotron image deleted succesfully'); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/***************************************************************************/ |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Save the record on DB. |
|
150
|
|
|
* @param \Illuminate\Http\Request $request |
|
151
|
|
|
* @param \DavideCasiraghi\LaravelJumbotronImages\Models\JumbotronImage $jumbotronImage |
|
152
|
|
|
* @return void |
|
153
|
|
|
*/ |
|
154
|
|
|
public function saveOnDb($request, $jumbotronImage) |
|
155
|
|
|
{ |
|
156
|
|
|
$jumbotronImage->translateOrNew('en')->text = $request->get('title'); |
|
157
|
|
|
$jumbotronImage->translateOrNew('en')->body = $request->get('body'); |
|
158
|
|
|
$jumbotronImage->translateOrNew('en')->button_text = $request->get('button_text'); |
|
159
|
|
|
$jumbotronImage->image_file_name = $request->get('image_file_name'); |
|
160
|
|
|
$jumbotronImage->button_url = $request->get('button_url'); |
|
161
|
|
|
|
|
162
|
|
|
$jumbotronImage->save(); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/***************************************************************************/ |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Display the specified resource. |
|
169
|
|
|
* |
|
170
|
|
|
* @return \Illuminate\Http\Response |
|
171
|
|
|
*/ |
|
172
|
|
|
public function showRandomJumbotronImage() |
|
173
|
|
|
{ |
|
174
|
|
|
$jumbotronImage = PhpResponsiveJumbotronImage::getRandomJumbotronImage(); |
|
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
// the view name is set in the - Service provider - boot - loadViewsFrom |
|
177
|
|
|
return view('laravel-jumbotron-images::show-random-quote', [ |
|
178
|
|
|
'quoteAuthor' => $jumbotronImage['author'], |
|
179
|
|
|
'quoteText' => $jumbotronImage['text'], |
|
180
|
|
|
]); |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.