diff --git a/app/Http/Controllers/MarhunController.php b/app/Http/Controllers/MarhunController.php index 8b9a8cac..8e1880fd 100644 --- a/app/Http/Controllers/MarhunController.php +++ b/app/Http/Controllers/MarhunController.php @@ -14,6 +14,7 @@ use App\Models\JenisKarat; use App\Models\Gadai; use App\Models\Lelong; use App\Models\CawanganLelong; +use App\Models\FileMarhun; use App\Models\LelongBid; use App\Models\LelongBidMarhun; use App\Models\LelKarat; @@ -411,8 +412,19 @@ class MarhunController extends Controller public function show($id, $lelong_id) { - $lelongbid = LelongBid::where('id','=',$id)->first(); - $marhun = LelongBidMarhun::where('lelongbid_id','=',$id)->get(); + $lelongbid = LelongBid::where('id', '=', $id)->first(); + $filemarhun = FileMarhun::where('lelongbid_id', '=', $lelongbid['id']) + ->where('photo_type', '=', '1')->first(); + if (isset($filemarhun)) { + $lelongbid->filemarhun = $filemarhun->filename; + } + $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; + } + } $lelkarat = LelKarat::where('lelong_id','=',$lelongbid->lelong_id)->get(); $karatall = JenisKarat::all(); $emasall = JenisEmas::all(); @@ -1119,5 +1131,29 @@ class MarhunController extends Controller return view('marhun.scanbarcode'); } + public function addPhotoMarhun(Request $request) { + $data = base64_encode($request->gambarMarhun->get()); + $file_type = $request->gambarMarhun->extension(); + + 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; + $addfile->photo_type = 2; + $addfile->file_type = $file_type; + $addfile->filename = $data; + $addfile->save(); + } + return redirect()->route('marhun.show', [$request->lelongbid_id, $request->lelong_id]) + ->with('success','Gambar Berjaya Di Simpan.'); + } } diff --git a/app/Models/FileMarhun.php b/app/Models/FileMarhun.php new file mode 100644 index 00000000..0d543e25 --- /dev/null +++ b/app/Models/FileMarhun.php @@ -0,0 +1,21 @@ +bigIncrements('id'); + $table->unsignedBigInteger('lelongbid_id')->unsigned(); + $table->unsignedBigInteger('lelongbidmarhun_id')->unsigned()->nullable(); + $table->unsignedBigInteger('photo_type')->unsigned(); + $table->string('file_type'); + $table->timestamps(); + }); + + // once the table is created use a raw query to ALTER it and add the MEDIUMBLOB + DB::statement("ALTER TABLE filemarhun ADD filename LONGBLOB"); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('filemarhun'); + } +} diff --git a/resources/views/marhun/marhun.blade.php b/resources/views/marhun/marhun.blade.php index e6473d4a..33df6a05 100644 --- a/resources/views/marhun/marhun.blade.php +++ b/resources/views/marhun/marhun.blade.php @@ -4,9 +4,11 @@
{{ $message }}