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