1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DavideCasiraghi\ResponsiveGallery\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Validator; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use DavideCasiraghi\ResponsiveGallery\Models\GalleryImage; |
8
|
|
|
use DavideCasiraghi\ResponsiveGallery\Facades\ResponsiveGallery; |
9
|
|
|
|
10
|
|
|
class ResponsiveGalleryController |
11
|
|
|
{ |
12
|
|
|
public function __invoke() |
13
|
|
|
{ |
14
|
|
|
//return ResponsiveGallery::getRandomQuote(); |
15
|
|
|
$galleryImages = GalleryImage::orderBy('file_name')->paginate(20); |
16
|
|
|
|
17
|
|
|
return view('vendor.laravel-responsive-gallery.index', compact('galleryImages')) |
18
|
|
|
->with('i', (request()->input('page', 1) - 1) * 20); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/***************************************************************************/ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Display a listing of the resource. |
25
|
|
|
* |
26
|
|
|
* @return \Illuminate\Http\Response |
27
|
|
|
*/ |
28
|
1 |
|
public function index(Request $request) |
29
|
|
|
{ |
30
|
1 |
|
$searchKeywords = $request->input('keywords'); |
31
|
|
|
|
32
|
1 |
|
if ($searchKeywords) { |
33
|
|
|
$galleryImages = GalleryImage::orderBy('file_name') |
34
|
|
|
->where('file_name', 'like', '%'.$request->input('keywords').'%') |
35
|
|
|
->paginate(20); |
36
|
|
|
} else { |
37
|
1 |
|
$galleryImages = GalleryImage::orderBy('file_name') |
38
|
1 |
|
->paginate(20); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return view('vendor.laravel-responsive-gallery.index', compact('galleryImages')) |
42
|
|
|
->with('i', (request()->input('page', 1) - 1) * 20) |
43
|
|
|
->with('searchKeywords', $searchKeywords); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/***************************************************************************/ |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Show the form for creating a new resource. |
50
|
|
|
* |
51
|
|
|
* @return \Illuminate\Http\Response |
52
|
|
|
*/ |
53
|
|
|
public function create() |
54
|
|
|
{ |
55
|
|
|
return view('vendor.laravel-responsive-gallery.create'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/***************************************************************************/ |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Store a newly created resource in storage. |
62
|
|
|
* |
63
|
|
|
* @param \Illuminate\Http\Request $request |
64
|
|
|
* @return \Illuminate\Http\Response |
65
|
|
|
*/ |
66
|
|
|
public function store(Request $request) |
67
|
|
|
{ |
68
|
|
|
|
69
|
|
|
// Validate form datas |
70
|
|
|
$validator = Validator::make($request->all(), [ |
71
|
|
|
'file_name' => 'required', |
72
|
|
|
]); |
73
|
|
|
if ($validator->fails()) { |
74
|
|
|
return back()->withErrors($validator)->withInput(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$gallery_image = new GalleryImage(); |
78
|
|
|
$gallery_image->file_name = $request->get('file_name'); |
|
|
|
|
79
|
|
|
$gallery_image->description = $request->get('description'); |
|
|
|
|
80
|
|
|
$gallery_image->alt = $request->get('alt'); |
|
|
|
|
81
|
|
|
$gallery_image->video_link = $request->get('video_link'); |
|
|
|
|
82
|
|
|
|
83
|
|
|
$gallery_image->save(); |
84
|
|
|
|
85
|
|
|
return redirect()->route('responsive-gallery.index') |
86
|
|
|
->with('success', 'Image datas added succesfully'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/***************************************************************************/ |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Display the specified resource. |
93
|
|
|
* |
94
|
|
|
* @param \App\Country $country |
|
|
|
|
95
|
|
|
* @return \Illuminate\Http\Response |
96
|
|
|
*/ |
97
|
|
|
public function show(GalleryImage $galleryImage) |
98
|
|
|
{ |
99
|
|
|
return view('vendor.laravel-responsive-gallery.show', compact('galleryImage')); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/***************************************************************************/ |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Show the form for editing the specified resource. |
106
|
|
|
* |
107
|
|
|
* @param \App\Country $country |
108
|
|
|
* @return \Illuminate\Http\Response |
109
|
|
|
*/ |
110
|
|
|
public function edit($id = null) |
111
|
|
|
{ |
112
|
|
|
$galleryImage = GalleryImage::find($id); |
113
|
|
|
|
114
|
|
|
return view('vendor.laravel-responsive-gallery.edit', compact('galleryImage')); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/***************************************************************************/ |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Update the specified resource in storage. |
121
|
|
|
* |
122
|
|
|
* @param \Illuminate\Http\Request $request |
123
|
|
|
* @param \App\Country $country |
124
|
|
|
* @return \Illuminate\Http\Response |
125
|
|
|
*/ |
126
|
|
|
public function update(Request $request, $id) |
127
|
|
|
{ |
128
|
|
|
request()->validate([ |
129
|
|
|
'file_name' => 'required', |
130
|
|
|
]); |
131
|
|
|
|
132
|
|
|
$galleryImage = GalleryImage::find($id); |
133
|
|
|
|
134
|
|
|
$galleryImage->update($request->all()); |
135
|
|
|
|
136
|
|
|
return redirect()->route('responsive-gallery.index') |
137
|
|
|
->with('success', 'Image datas updated succesfully'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/***************************************************************************/ |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Remove the specified resource from storage. |
144
|
|
|
* |
145
|
|
|
* @param \App\Country $country |
146
|
|
|
* @return \Illuminate\Http\Response |
147
|
|
|
*/ |
148
|
|
|
public function destroy($id) |
149
|
|
|
{ |
150
|
|
|
$galleryImage = GalleryImage::find($id); |
151
|
|
|
$galleryImage->delete(); |
152
|
|
|
|
153
|
|
|
return redirect()->route('responsive-gallery.index') |
154
|
|
|
->with('success', 'Image datas deleted succesfully'); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.