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 +++++--- resources/views/pages/gallery.blade.php | 23 +++++++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) 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.'); } } diff --git a/resources/views/pages/gallery.blade.php b/resources/views/pages/gallery.blade.php index 84b8daf..f4462fe 100644 --- a/resources/views/pages/gallery.blade.php +++ b/resources/views/pages/gallery.blade.php @@ -4,7 +4,26 @@ @section('content')
- YOTA camp - YOTA + {{--YOTA camp--}} + {{--YOTA--}} + @if (count($images) > 0) + @foreach ($images as $image) +
+
+
+ {{ $image->name }} +
+ @auth +
+ Delete +
+ @endauth +
+
+ @endforeach + {{ $images->links() }} + @else + There are currently no images in gallery. + @endif
@endsection() -- cgit v1.2.3