frefactor(daftar-pustaka): replace manual file handling with Laravel Storage
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user