fix: change path download template and add template pariwisata

This commit is contained in:
2025-02-20 10:36:56 +07:00
parent f10bc153b4
commit dcd93d66e2
6 changed files with 20 additions and 4 deletions

View File

@@ -199,7 +199,7 @@ class AdvertisementController extends Controller
public function downloadExcelAdvertisement() public function downloadExcelAdvertisement()
{ {
$filePath = storage_path('app/public/templates/template_reklame.xlsx'); $filePath = public_path('templates/template_reklame.xlsx');
// Cek apakah file ada // Cek apakah file ada
if (!file_exists($filePath)) { if (!file_exists($filePath)) {

View File

@@ -127,4 +127,18 @@ class TourismController extends Controller
return response()->noContent(); return response()->noContent();
} }
public function downloadExcelTourism()
{
$filePath = public_path('templates/template_pariwisata.xlsx');
info(sprintf("File Path: %s | Exists: %s", $filePath, file_exists($filePath) ? 'Yes' : 'No'));
// Cek apakah file ada
if (!file_exists($filePath)) {
return response()-> json(['message' => 'File tidak ditemukan!'], Response::HTTP_NOT_FOUND);
}
// Return file to download
return response()->download($filePath);
}
} }

View File

@@ -176,7 +176,7 @@ class UmkmController extends Controller
public function downloadExcelUmkm() public function downloadExcelUmkm()
{ {
$filePath = storage_path('app/public/templates/template_umkm.xlsx'); $filePath = public_path('templates/template_umkm.xlsx');
// Cek apakah file ada // Cek apakah file ada
if (!file_exists($filePath)) { if (!file_exists($filePath)) {

Binary file not shown.

View File

@@ -88,7 +88,7 @@ dropzone.on("complete", function(file) {
// Add event listener to download file template // Add event listener to download file template
document.getElementById('downloadtemptourisms').addEventListener('click', function() { document.getElementById('downloadtemptourisms').addEventListener('click', function() {
var url = `${GlobalConfig.apiHost}/api/download-template-umkm`; var url = `${GlobalConfig.apiHost}/api/download-template-tourism`;
fetch(url, { fetch(url, {
method: 'GET', method: 'GET',
headers: { headers: {
@@ -105,11 +105,12 @@ document.getElementById('downloadtemptourisms').addEventListener('click', functi
} }
}) })
.then((blob) => { .then((blob) => {
console.log(blob);
const url = window.URL.createObjectURL(blob); const url = window.URL.createObjectURL(blob);
const a = document.createElement('a'); const a = document.createElement('a');
a.style.display = 'none'; a.style.display = 'none';
a.href = url; a.href = url;
a.download = 'template_tourisms.xlsx'; a.download = 'template_pariwisata.xlsx';
document.body.appendChild(a); document.body.appendChild(a);
a.click(); a.click();
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);

View File

@@ -65,6 +65,7 @@ Route::group(['middleware' => 'auth:sanctum'], function (){
//tourism //tourism
Route::apiResource('tourisms', TourismController::class); Route::apiResource('tourisms', TourismController::class);
Route::post('/tourisms/import', [TourismController::class, 'importFromFile']); Route::post('/tourisms/import', [TourismController::class, 'importFromFile']);
Route::get('/download-template-tourism', [TourismController::class, 'downloadExcelTourism']);
// data-settings // data-settings