From d64ceaaa73f9053a4787853a7c06758f6af53d65 Mon Sep 17 00:00:00 2001 From: Mateja Date: Sat, 7 Nov 2020 01:02:57 +0100 Subject: Gallery finished... --- app/Http/Controllers/GalleryController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'app/Http/Controllers/GalleryController.php') diff --git a/app/Http/Controllers/GalleryController.php b/app/Http/Controllers/GalleryController.php index db0f956..064be02 100644 --- a/app/Http/Controllers/GalleryController.php +++ b/app/Http/Controllers/GalleryController.php @@ -20,7 +20,8 @@ class GalleryController extends Controller */ public function index() { - return view('pages.gallery'); + $images = Image::paginate(9); + return view('pages.gallery', compact('images')); } /** @@ -47,7 +48,7 @@ class GalleryController extends Controller $images = $request->file('images'); foreach ($images as $image) { $path = 'imgs/'; - $name = time() . '.' . $image->getClientOriginalExtension(); + $name = time() . '.' . uniqid() . '.' . $image->getClientOriginalExtension(); $image->move($path, $name); $save = new Image(); @@ -101,6 +102,7 @@ class GalleryController extends Controller */ public function destroy($id) { - return Redirect::back(); + Image::findOrFail($id)->delete(); + return Redirect::back()->with('status', 'Image deleted.'); } } -- cgit v1.2.3