delete, update photo marhun

This commit is contained in:
Amir
2022-09-05 14:33:58 +08:00
parent 2327b98b30
commit cf972c0d68
3 changed files with 153 additions and 46 deletions
+46 -15
View File
@@ -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.');
}
}