add photo marhun

This commit is contained in:
Amir
2022-09-05 09:09:21 +08:00
parent 996665a3ee
commit 71842138bf
6 changed files with 124 additions and 47 deletions
+33 -13
View File
@@ -412,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();
@@ -1120,20 +1131,29 @@ class MarhunController extends Controller
return view('marhun.scanbarcode');
}
public function savePhotoOverallMarhun(Request $request) {
// dump($request->gambarMarhun);
public function addPhotoMarhun(Request $request) {
$data = base64_encode($request->gambarMarhun->get());
$file_type = $request->gambarMarhun->extension();
$addfile = new FileMarhun();
$addfile->file_type = $file_type;
$addfile->filename = $data;
$addfile->save();
// dd($addfile);
}
public function savePhotoEachMarhun() {
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.');
}
}
+1
View File
@@ -14,6 +14,7 @@ class FileMarhun extends Model
protected $fillable = [
'lelongbid_id',
'lelongbidmarhun_id',
'photo_type', //1-overall_marhun, 2-each_marhun
'file_type',
'filename',
];
@@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
class CreateFileTable extends Migration
{
@@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
class CreateFilemarhunTable extends Migration
{
@@ -15,8 +16,9 @@ class CreateFilemarhunTable extends Migration
{
Schema::create('filemarhun', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('lelongbid_id')->unsigned()->nullable();
$table->unsignedBigInteger('lelongbid_id')->unsigned();
$table->unsignedBigInteger('lelongbidmarhun_id')->unsigned()->nullable();
$table->unsignedBigInteger('photo_type')->unsigned();
$table->string('file_type');
$table->timestamps();
});
+85 -31
View File
@@ -4,9 +4,11 @@
<div class="container-fluid">
<div class="row ">
<div class="col-md-11 mx-auto card p-4">
<div class="row">
<a href=" {{ route('marhun.senaraimarhun', ['lelong_id'=>$lelongbid->lelong_id]) }}" class="btn btn-secondary">Kembali</a>
</div>
@if ($message = Session::get('success'))
<div class="alert alert-success">
<div class="alert mt-2 alert-success">
<p>{{ $message }}</p>
</div>
@endif
@@ -28,15 +30,16 @@
<div class="row justify-content-center">
<div class="col-6">
<div class="card">
<div class="card-header">Thumbnail marhun</div>
<div class="card-body">
-Tiada Data-
</div>
<div class="card-footer">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modaluploadgambar">
butiran marhun
<div class="card-header">Keseluruhan Marhun</div>
<div class="card-body" style="align-self: center; justify-content: center;">
@if ($lelongbid['filemarhun'] != null)
<button type="button" data-toggle="modal" onclick="kesulurahanMarhunData(this)" data-keseluruhanMarhun="{{ $lelongbid['filemarhun'] }}" data-target="#modaloverallphoto">
<img src="data:image/png;base64, {{ $lelongbid['filemarhun'] }}" alt="Image Preview" style="max-width:300px; border: 1px solid #dee2e6" />
</button>
@else
<p>Tiada Data</p>
<button type="button" data-toggle="modal" data-target="#modaloverallphoto">Muat Naik Gambar</button>
@endif
</div>
</div>
</div>
@@ -62,7 +65,11 @@
@foreach ($marhun as $item)
<tr>
<td class="text-center"> {{ $loop->iteration }} </td>
<td class="p-2 m-2" style="border: 1px solid black; width: 100px; height: 130px"><button data-toggle="modal" data-target="#modaluploadgambar">butiran marhun</button></td>
<td class="p-2 m-2" style="border: 1px solid black; width: 100px; height: 130px">
<button data-toggle="modal" onclick="marhunData(this)" data-loop="{{$loop->iteration}}" data-marhun="{{$item->marhun}}" data-id="{{$item->id}}" data-target="#modaleachphoto">
<img src="data:image/png;base64, {{ $item->eachmarhun }}" alt="Tambah / Padam Gambar" style="max-width:100px; border: 1px solid #dee2e6" />
</button>
</td>
<td>{{ $item->marhun }}</td>
<td>
@if($item->karat != null)
@@ -245,27 +252,68 @@
</div>
</div>
</div>
<div class="modal fade" tabindex="-1" id="modaluploadgambar">
<div class="modal fade" data-backdrop="static" data-keyboard="false" tabindex="-1" id="modaloverallphoto">
<div class="modal-dialog modal-dialog-centered modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">thumbnail marhun</h5>
<h5 class="modal-title">Keseluruhan Marhun</h5>
<button type="button" class="close" onclick="clearData()" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form id="form1" action="{{route('marhun.addphotomarhun')}}" method="POST" enctype="multipart/form-data">
@csrf
<input type="hidden" name="lelongbid_id" value="{{ $lelongbid['id'] }}">
<input type="hidden" name="lelong_id" value="{{ $lelongbid['lelong_id'] }}">
<input type="hidden" name="photo_type" value="1">
<div class="modal-body justify-content-center">
@if (!isset($lelongbid->filemarhun))
<div class="row justify-content-center">
<div class="col-8">
<input type="file" accept="image/*;capture=camera" name="gambarMarhun" id="inputGroupFile04" /><br>
</div>
</div>
@else
<div class="row mt-5 justify-content-center">
<button data-dismiss="modal" class="btn m-2 btn-warning">tukar gambar</button>
<button data-dismiss="modal" class="btn m-2 btn-danger">padam gambar</button>
</div>
@endif
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" style="width:15%;" onclick="clearData()" data-dismiss="modal">Kembali</button>
<button type="submit" class="btn btn-primary" style="width:15%;">Simpan</button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" data-backdrop="static" data-keyboard="false" tabindex="-1" id="modaleachphoto">
<div class="modal-dialog modal-dialog-centered modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="titleHeader" value="titleHeader">Marhun, Bil:</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form id="form1" action="{{route('marhun.savephotooverallmarhun')}}" method="POST" enctype="multipart/form-data">
<form id="form1" action="{{route('marhun.addphotomarhun')}}" method="POST" enctype="multipart/form-data">
@csrf
<input type="hidden" name="lelongbid_id" value="{{ $lelongbid['id'] }}">
<input type="hidden" name="lelong_id" value="{{ $lelongbid['lelong_id'] }}">
<input type="hidden" name="photo_type" value="2">
<input type="hidden" name="lelongbidmarhun_id" id="marhun_id" value="">
<div class="modal-body justify-content-center">
<div class="row justify-content-center">
<!-- <div class="row justify-content-center">
<img id="blah" style="max-width: 400px; max-height: 400px;" src="#" alt="gambar marhun" />
</div>
</div> -->
<div class="row justify-content-center">
<input type='file' accept="image/*;capture=camera" name="gambarMarhun" id="inputGroupFile04" /><br>
<input type='file' accept="image/*;capture=camera" name="gambarMarhun" id="inputGroupFile04" /><br>
</div>
<div class="row mt-5 justify-content-center">
<button type='file' accept="image/*;capture=camera" class="btn m-2 btn-warning">tukar gambar</button>
<button class="btn m-2 btn-danger">padam gambar</button>
<button data-dismiss="modal" class="btn m-2 btn-warning">tukar gambar</button>
<button data-dismiss="modal" class="btn m-2 btn-danger">padam gambar</button>
</div>
</div>
<div class="modal-footer">
@@ -279,21 +327,27 @@
</div>
</div>
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
function clearData() {
document.getElementById('inputGroupFile04').value = '';
}
function marhunData(value) {
id = $(value).data('id');
console.log(id);
marhun = $(value).data('marhun');
loop = $(value).data('loop');
document.getElementById('marhun_id').value = id;
document.getElementById("titleHeader").innerHTML = "Bil:" + loop + ", Id Marhun:" + id + ", Marhun:" + marhun;
}
function kesulurahanMarhunData(value) {
console.log(value);
keseluruhanMarhun = $(value).data('keseluruhanMarhun');
document.getElementById('marhun_id').value = keseluruhanMarhun;
reader.onload = function(e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function() {
readURL(this);
});
function confirm() {
$.confirm({
+1 -2
View File
@@ -241,8 +241,7 @@ Route::group(['middleware' => ['permission:semakanmarhun','permission:kemaskinim
Route::get('/exportmarhundetails/{lelong_id}',['as'=>'marhun.exportmarhundetails','uses'=>'MarhunController@exportmarhundetails']);
//Penilai
Route::post('/savephotooverallmarhun',['as'=>'marhun.savephotooverallmarhun','uses'=>'MarhunController@savePhotoOverallMarhun']);
Route::post('/addphotomarhun',['as'=>'marhun.addphotomarhun','uses'=>'MarhunController@addPhotoMarhun']);
});
//Khazanah