aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Http/Controllers/GalleryController.php8
-rw-r--r--resources/views/pages/gallery.blade.php23
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')
<div class="row">
- <img class="col-lg-6 mb-3 mb-lg-0" src="/imgs/camp.png" alt="YOTA camp"/>
- <img class="col-lg-6 mb-3 mb-lg-0" src="/imgs/yota.jpg" alt="YOTA"/>
+ {{--<img class="col-lg-6 mb-3 mb-lg-0" src="/imgs/camp.png" alt="YOTA camp"/>--}}
+ {{--<img class="col-lg-6 mb-3 mb-lg-0" src="/imgs/yota.jpg" alt="YOTA"/>--}}
+ @if (count($images) > 0)
+ @foreach ($images as $image)
+ <div class="col-lg-6">
+ <div class="card mb-3">
+ <div class="card-img-top">
+ <img class="img-fluid" src="{{ asset($image->path . $image->name) }}" alt="{{ $image->name }}" loading="lazy">
+ </div>
+ @auth
+ <div class="card-body">
+ <a class="btn btn-danger" href="{{ route('galleryDelete', $image->id) }}">Delete</a>
+ </div>
+ @endauth
+ </div>
+ </div>
+ @endforeach
+ {{ $images->links() }}
+ @else
+ <strong class="text-center">There are currently no images in gallery.</strong>
+ @endif
</div>
@endsection()