From e4fec1b5386c19a7c0bfb28b850862159c8710dd Mon Sep 17 00:00:00 2001 From: Mateja Date: Sat, 7 Nov 2020 00:10:15 +0100 Subject: Work on gallery... --- app/Http/Controllers/GalleryController.php | 25 ++++++++++++++++++++-- .../2020_11_06_185340_create_images_table.php | 2 +- resources/views/pages/gallery-add.blade.php | 13 ++++++++++- routes/web.php | 2 +- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/GalleryController.php b/app/Http/Controllers/GalleryController.php index 8f42b48..3f11997 100644 --- a/app/Http/Controllers/GalleryController.php +++ b/app/Http/Controllers/GalleryController.php @@ -4,6 +4,13 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use dd; + +use Illuminate\Support\Facades\Redirect; +use Illuminate\Support\Facades\Validator; + +use App\Models\Image; + class GalleryController extends Controller { /** @@ -34,7 +41,21 @@ class GalleryController extends Controller */ public function store(Request $request) { - // + $validatedData = $request->validate([ + 'images' => 'required' + ]); + $images = $request->file('images'); + foreach ($images as $image) { + $save = new Image(); + $save->path = 'imgs/'; + $save->name = time() . '.' . $image->getClientOriginalExtension(); + + $image->storeAs($save->path, $save->name); + + $save->save(); + } + + return Redirect::back(); } /** @@ -79,6 +100,6 @@ class GalleryController extends Controller */ public function destroy($id) { - // + return Redirect::back(); } } diff --git a/database/migrations/2020_11_06_185340_create_images_table.php b/database/migrations/2020_11_06_185340_create_images_table.php index 5c03545..98b070d 100644 --- a/database/migrations/2020_11_06_185340_create_images_table.php +++ b/database/migrations/2020_11_06_185340_create_images_table.php @@ -16,7 +16,7 @@ class CreateImagesTable extends Migration Schema::create('images', function (Blueprint $table) { $table->id(); $table->string('name'); - $table->string('path'); + $table->string('path', 255); $table->timestamps(); }); } diff --git a/resources/views/pages/gallery-add.blade.php b/resources/views/pages/gallery-add.blade.php index 2d0ec27..868f212 100644 --- a/resources/views/pages/gallery-add.blade.php +++ b/resources/views/pages/gallery-add.blade.php @@ -5,8 +5,19 @@ @section('content')
@csrf + @if ($errors->any()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif
- + +
+
diff --git a/routes/web.php b/routes/web.php index 02b5107..fc9297e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -33,7 +33,7 @@ Route::get('/news/delete/{id}', [NewsController::class, 'destroy'])->name('newsD Route::get('/gallery', [GalleryController::class, 'index'])->name('gallery'); Route::get('/gallery/add', [GalleryController::class, 'create'])->name('galleryAdd')->middleware(['auth']); -Route::post('/gallery/add', [GalleryController::class, 'create'])->name('galleryAddForm')->middleware(['auth']); +Route::post('/gallery/add', [GalleryController::class, 'store'])->name('galleryAddForm')->middleware(['auth']); Route::get('/gallery/delete/{id}', [GalleryController::class, 'destroy'])->name('galleryDelete')->middleware(['auth']); -- cgit v1.2.3