frefactor(daftar-pustaka): replace manual file handling with Laravel Storage

This commit is contained in:
majid
2025-07-08 14:17:45 +07:00
parent 6bb13dbcaf
commit 05f87f4767

View File

@@ -50,7 +50,7 @@ class DaftarPustakaService
// get all with pagination // get all with pagination
public function getAllDaftarPustaka($request) public function getAllDaftarPustaka($request)
{ {
$query = DaftarPustaka::query(); $query = DaftarPustaka::query();
// Filter pencarian // Filter pencarian
@@ -72,7 +72,7 @@ class DaftarPustakaService
$size = (int) $request->get('size', 10); $size = (int) $request->get('size', 10);
return $query->paginate($size, ['*'], 'page', $page); return $query->paginate($size, ['*'], 'page', $page);
} }
private function handleUpload($file) private function handleUpload($file)
@@ -80,14 +80,10 @@ class DaftarPustakaService
$today = now(); $today = now();
$folderPath = 'daftar_pustaka/' . $today->format('Y/m/d'); $folderPath = 'daftar_pustaka/' . $today->format('Y/m/d');
if (!file_exists(public_path($folderPath))) {
mkdir(public_path($folderPath), 0755, true);
}
$fileName = $file->getClientOriginalName(); $fileName = $file->getClientOriginalName();
$file->move(public_path($folderPath), $fileName); $filePath = $file->storeAs($folderPath, $fileName, 'public');
return $folderPath . '/' . $fileName; return $filePath;
} }