From cf972c0d68ae469858ce14b4901fcfda81738a5a Mon Sep 17 00:00:00 2001 From: Amir Date: Mon, 5 Sep 2022 14:33:58 +0800 Subject: [PATCH] delete, update photo marhun --- app/Http/Controllers/MarhunController.php | 61 +++++++--- resources/views/marhun/marhun.blade.php | 136 +++++++++++++++++----- routes/web.php | 2 + 3 files changed, 153 insertions(+), 46 deletions(-) diff --git a/app/Http/Controllers/MarhunController.php b/app/Http/Controllers/MarhunController.php index 8e1880fd..de9c2462 100644 --- a/app/Http/Controllers/MarhunController.php +++ b/app/Http/Controllers/MarhunController.php @@ -416,13 +416,15 @@ class MarhunController extends Controller $filemarhun = FileMarhun::where('lelongbid_id', '=', $lelongbid['id']) ->where('photo_type', '=', '1')->first(); if (isset($filemarhun)) { - $lelongbid->filemarhun = $filemarhun->filename; + $lelongbid->filemarhun_filename = $filemarhun->filename; + $lelongbid->filemarhun_id = $filemarhun->id; } $marhun = LelongBidMarhun::where('lelongbid_id', '=', $id)->get(); foreach ($marhun as $index) { $eachmarhun = FileMarhun::where('lelongbidmarhun_id', '=', $index['id'])->first(); if (isset($eachmarhun)) { - $index->eachmarhun = $eachmarhun->filename; + $index->eachmarhun_filename = $eachmarhun->filename; + $index->eachmarhun_id = $eachmarhun->id; } } $lelkarat = LelKarat::where('lelong_id','=',$lelongbid->lelong_id)->get(); @@ -1131,29 +1133,58 @@ class MarhunController extends Controller return view('marhun.scanbarcode'); } - public function addPhotoMarhun(Request $request) { + public function addPhotoMarhun(Request $request) + { $data = base64_encode($request->gambarMarhun->get()); $file_type = $request->gambarMarhun->extension(); + $addfile = new FileMarhun(); + $addfile->lelongbid_id = $request->lelongbid_id; + $addfile->file_type = $file_type; + $addfile->filename = $data; if ($request->photo_type == 1) { - $addfile = new FileMarhun(); - $addfile->lelongbid_id = $request->lelongbid_id; $addfile->photo_type = 1; - $addfile->file_type = $file_type; - $addfile->filename = $data; $addfile->save(); - } - else if ($request->photo_type == 2) { - $addfile = new FileMarhun(); - $addfile->lelongbid_id = $request->lelongbid_id; - $addfile->lelongbidmarhun_id = $request->lelongbidmarhun_id; + } else if ($request->photo_type == 2) { $addfile->photo_type = 2; - $addfile->file_type = $file_type; - $addfile->filename = $data; + $addfile->lelongbidmarhun_id = $request->lelongbidmarhun_id; $addfile->save(); } return redirect()->route('marhun.show', [$request->lelongbid_id, $request->lelong_id]) - ->with('success','Gambar Berjaya Di Simpan.'); + ->with('success', 'Gambar Berjaya Di Simpan.'); + } + + public function deletePhotoMarhun(Request $request) + { + $deleteFile = FileMarhun::where('id', '=', $request->filemarhun_id)->first(); + $deleteFile->delete(); + + return redirect()->route('marhun.show', [$request->lelongbid_id, $request->lelong_id]) + ->with('success', 'Gambar Berjaya Di Padam.'); + } + + public function updatePhotoMarhun(Request $request) + { + $data = base64_encode($request->gambarMarhun->get()); + $file_type = $request->gambarMarhun->extension(); + + $addfile = new FileMarhun(); + $addfile->lelongbid_id = $request->lelongbid_id; + $addfile->file_type = $file_type; + $addfile->filename = $data; + if ($request->photo_type == 1) { + $addfile->photo_type = 1; + $addfile->save(); + } else if ($request->photo_type == 2) { + $addfile->photo_type = 2; + $addfile->lelongbidmarhun_id = $request->lelongbidmarhun_id; + $addfile->save(); + } + $deleteFile = FileMarhun::where('id', '=', $request->filemarhun_id)->first(); + $deleteFile->delete(); + + return redirect()->route('marhun.show', [$request->lelongbid_id, $request->lelong_id]) + ->with('success', 'Gambar Berjaya Di Tukar.'); } } diff --git a/resources/views/marhun/marhun.blade.php b/resources/views/marhun/marhun.blade.php index 33df6a05..f0eac3c6 100644 --- a/resources/views/marhun/marhun.blade.php +++ b/resources/views/marhun/marhun.blade.php @@ -5,13 +5,19 @@
@if ($message = Session::get('success'))

{{ $message }}

@endif +
+ @csrf + + + +
@csrf @@ -32,9 +38,9 @@
Keseluruhan Marhun
- @if ($lelongbid['filemarhun'] != null) - @else

Tiada Data

@@ -61,13 +67,12 @@ - @foreach ($marhun as $item) {{ $loop->iteration }} - {{ $item->marhun }} @@ -186,7 +191,7 @@
@@ -245,7 +250,7 @@
@@ -267,7 +272,7 @@