Change store marhun photo to file from db, add feature to view full marhun photo
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Models\FileMarhun;
|
||||
|
||||
class MarhunPhotoService
|
||||
{
|
||||
|
||||
public function store(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();
|
||||
} elseif ($request->photo_type == 2) {
|
||||
$addfile->photo_type = 2;
|
||||
$addfile->lelongbidmarhun_id = $request->lelongbidmarhun_id;
|
||||
$addfile->save();
|
||||
}
|
||||
|
||||
$directory = "/{$request->lelongbid_id}/{$request->lelong_id}/{$request->photo_type}/";
|
||||
$imageExtension = $request->file('gambarMarhun')->getClientOriginalExtension();
|
||||
|
||||
$marhunImageFileName = "overall.{$imageExtension}";
|
||||
|
||||
if (!empty($request->lelongbidmarhun_id)) {
|
||||
$marhunImageFileName = "$request->lelongbidmarhun_id.$imageExtension";
|
||||
}
|
||||
|
||||
Storage::disk('marhun')->putFileAs($directory, $request->gambarMarhun, $marhunImageFileName);
|
||||
}
|
||||
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$deleteFile = FileMarhun::where('id', '=', $request->filemarhun_id)->first();
|
||||
|
||||
$lelongbid_id = $deleteFile->lelongbid_id;
|
||||
$lelongbidmarhun_id = $deleteFile->lelongbidmarhun_id;
|
||||
$lelong_id = $request->lelong_id;
|
||||
$photo_type = $deleteFile->photo_type;
|
||||
|
||||
$directory = "/{$lelongbid_id}/{$lelong_id}/{$photo_type}/";
|
||||
$imageExtension = $deleteFile->file_type;
|
||||
|
||||
$marhunImageFileName = "overall.{$imageExtension}";
|
||||
|
||||
if (!empty($request->lelongbidmarhund_id)) {
|
||||
$marhunImageFileName = "$lelongbidmarhun_id.$imageExtension";
|
||||
}
|
||||
|
||||
Storage::disk('marhun')->delete("{$directory}${marhunImageFileName}");
|
||||
$deleteFile->delete();
|
||||
}
|
||||
|
||||
public function show($lelong_id, $marhun)
|
||||
{
|
||||
$lelongbid_id = $marhun->lelongbid_id;
|
||||
$lelongbidmarhun_id = $marhun->lelongbidmarhun_id;
|
||||
$lelong_id = $lelong_id;
|
||||
$photo_type = $marhun->photo_type;
|
||||
|
||||
$directory = "{$lelongbid_id}/{$lelong_id}/{$photo_type}/";
|
||||
$imageExtension = $marhun->file_type;
|
||||
|
||||
$marhunImageFileName = "overall.{$imageExtension}";
|
||||
|
||||
if (!empty($lelongbidmarhun_id)) {
|
||||
$marhunImageFileName = "$lelongbidmarhun_id.$imageExtension";
|
||||
}
|
||||
|
||||
|
||||
$filePath = Storage::disk('marhun')->path("{$directory}${marhunImageFileName}");
|
||||
|
||||
header('Content-Type:' . $imageExtension);
|
||||
header('Content-Length: ' . filesize($filePath));
|
||||
readfile($filePath);
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,13 @@ return [
|
||||
'root' => storage_path('app'),
|
||||
],
|
||||
|
||||
'marhun' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/marhun'),
|
||||
'url' => env('APP_URL').'/marhun_photo',
|
||||
'visibility' => 'public',
|
||||
],
|
||||
|
||||
'public' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/public'),
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
data-lelongid="{{ $lelongbid['lelong_id'] }}"
|
||||
data-lelongbidid="{{ $lelongbid['id'] }}"
|
||||
data-fileid="{{ $lelongbid['filemarhun_id'] }}" data-target="#modaloverallphoto">
|
||||
<img src="data:image/png;base64, {{ $lelongbid['filemarhun_filename'] }}"
|
||||
<img src="{{ route('marhun.showphotomarhun', ['lelong_id' => $lelongbid['lelong_id'], 'filemarhun_id' => $lelongbid['filemarhun_id']]) }}"
|
||||
alt="Image Preview" style="max-width:300px; border: 1px solid #dee2e6" />
|
||||
</button>
|
||||
@else
|
||||
@@ -135,8 +135,7 @@
|
||||
data-filename="{{ $item->eachmarhun_filename }}"
|
||||
data-marhun="{{ $item->marhun }}" data-marhunid="{{ $item->id }}"
|
||||
data-target="#modaleachphoto">
|
||||
<img src="data:image/png;base64, {{ $item->eachmarhun_filename }}"
|
||||
alt="Tambah / Padam Gambar"
|
||||
<img src="{{ url($item->eachmarhun_filename) }}" alt="Tambah / Padam Gambar"
|
||||
style="max-width:100px; border: 1px solid #dee2e6" />
|
||||
</button>
|
||||
@endif
|
||||
@@ -411,9 +410,12 @@
|
||||
</div>
|
||||
@else
|
||||
<div class="row mt-5 justify-content-center">
|
||||
<button data-dismiss="modal" onclick="updatePhoto(1)" type="button"
|
||||
data-target="#modalupdatephoto" data-toggle="modal"
|
||||
class="btn m-2 btn-warning">Upload Gambar Baru</button>
|
||||
@php
|
||||
$imageLink = route('marhun.showphotomarhun', ['lelong_id' => $lelongbid['lelong_id'], 'filemarhun_id' => $lelongbid['filemarhun_id']]);
|
||||
@endphp
|
||||
<a href="{{ $imageLink }}" target="_blank" class="btn m-2 btn-warning">Lihat gambar</a>
|
||||
<button data-dismiss="modal"
|
||||
type="button" class="btn m-2 btn-warning">Muat naik gambar baru</button>
|
||||
<button data-dismiss="modal"
|
||||
onclick="modalOverallPhotoCaptureUpdate.initiateTakeMarhunPhoto()" type="button"
|
||||
class="btn m-2 btn-warning">Ambil Gambar Baru</button>
|
||||
@@ -460,9 +462,9 @@
|
||||
id="inputGroupFile04" /><br>
|
||||
</div>
|
||||
<div id="updateDeletePhoto" hidden class="row mt-5 justify-content-center">
|
||||
<a href="" target="_blank" class="btn m-2 btn-warning viewPhotoEachMarhunLink">Lihat gambar</a>
|
||||
<button data-dismiss="modal" onclick="updatePhoto(2)" type="button"
|
||||
data-target="#modalupdatephoto" data-toggle="modal" class="btn m-2 btn-warning">Tukar
|
||||
Gambar</button>
|
||||
data-target="#modalupdatephoto" data-toggle="modal" class="btn m-2 btn-warning">Muat naik gambar baru</button>
|
||||
<button data-dismiss="modal"
|
||||
onclick="modalOverallPhotoCapturePerMarhunUpdate.initiateTakeMarhunPhoto()"
|
||||
type="button" data-toggle="modal" class="btn m-2 btn-warning">Ambil Gambar
|
||||
@@ -527,7 +529,6 @@
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
marhunPhotoCapturerReloadHttps.reload();
|
||||
|
||||
function clearData() {
|
||||
@@ -549,10 +550,17 @@
|
||||
|
||||
prepareModalUpdateCaptureEachMarhun(modalTitle, marhunId, fileId);
|
||||
prepareModalUpdateUploadEachMarhun(modalTitle, marhunId, fileId, fileName);
|
||||
prepareModalViewPhotoEachMarhun(fileName);
|
||||
|
||||
}
|
||||
|
||||
function prepareModalUpdateCaptureEachMarhun(modalTitle, marhunId, fileId){
|
||||
function prepareModalViewPhotoEachMarhun(fileName)
|
||||
{
|
||||
let modal = document.querySelector('#modaleachphoto');
|
||||
modal.querySelector('a.viewPhotoEachMarhunLink').href = fileName;
|
||||
}
|
||||
|
||||
function prepareModalUpdateCaptureEachMarhun(modalTitle, marhunId, fileId) {
|
||||
|
||||
let modal = document.querySelector('#modalpermarhunphoto-capture-update');
|
||||
modal.querySelector('#marhun_id').value = loop;
|
||||
@@ -561,7 +569,7 @@
|
||||
|
||||
}
|
||||
|
||||
function prepareModalUpdateUploadEachMarhun(modalTitle, marhunId, fileId, fileName){
|
||||
function prepareModalUpdateUploadEachMarhun(modalTitle, marhunId, fileId, fileName) {
|
||||
|
||||
if (fileName == '') {
|
||||
$("#createPhoto").attr("hidden", false);
|
||||
@@ -571,6 +579,8 @@
|
||||
$("#updateDeletePhoto").attr("hidden", false);
|
||||
}
|
||||
|
||||
let modal = document.querySelector('#modaleachphoto');
|
||||
modal.querySelector('input[name="lelongbidmarhun_id"]').value = marhunId;
|
||||
document.getElementById('marhun_id').value = marhunId;
|
||||
document.getElementById('filemarhun_id').value = fileId;
|
||||
document.getElementById("titleHeader").innerHTML = modalTitle;
|
||||
|
||||
@@ -283,6 +283,7 @@ Route::group(['middleware' => ['permission:semakanmarhun','permission:kemaskinim
|
||||
Route::post('/addphotomarhun',['as'=>'marhun.addphotomarhun','uses'=>'MarhunController@addPhotoMarhun']);
|
||||
Route::post('/deletephotomarhun',['as'=>'marhun.deletephotomarhun','uses'=>'MarhunController@deletePhotoMarhun']);
|
||||
Route::post('/updatephotomarhun',['as'=>'marhun.updatephotomarhun','uses'=>'MarhunController@updatePhotoMarhun']);
|
||||
Route::get('/showphotomarhun',['as'=>'marhun.showphotomarhun','uses'=>'MarhunController@showPhotoMarhun']);
|
||||
Route::get('/cetakterimaserahmarhun/{lelong_id}',['as'=>'marhun.cetakterimaserahmarhun','uses'=>'MarhunController@cetakterimaserahmarhun']);
|
||||
Route::get('/senaraiterimaserah',['as'=>'marhun.senaraiterimaserah','uses'=>'MarhunController@senaraiterimaserah']);
|
||||
Route::post('/cetakterimaserah',['as'=>'marhun.cetakterimaserah','uses'=>'MarhunController@cetakterimaserah']);
|
||||
|
||||
Reference in New Issue
Block a user