frefactor(daftar-pustaka): replace manual file handling with Laravel Storage
This commit is contained in:
@@ -50,44 +50,40 @@ 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
|
||||||
if (!empty($request->get('search'))) {
|
if (!empty($request->get('search'))) {
|
||||||
$search = $request->get('search');
|
$search = $request->get('search');
|
||||||
$query->where(function ($q) use ($search) {
|
$query->where(function ($q) use ($search) {
|
||||||
$q->orWhere('judul', 'LIKE', "%$search%");
|
$q->orWhere('judul', 'LIKE', "%$search%");
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter kategori
|
||||||
|
if (!empty($request->get('category'))) {
|
||||||
|
$category = explode(',', $request->input('category'));
|
||||||
|
$query->whereIn('category_id', $category);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default pagination
|
||||||
|
$page = (int) $request->get('page', 1);
|
||||||
|
$size = (int) $request->get('size', 10);
|
||||||
|
|
||||||
|
return $query->paginate($size, ['*'], 'page', $page);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter kategori
|
|
||||||
if (!empty($request->get('category'))) {
|
|
||||||
$category = explode(',', $request->input('category'));
|
|
||||||
$query->whereIn('category_id', $category);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default pagination
|
|
||||||
$page = (int) $request->get('page', 1);
|
|
||||||
$size = (int) $request->get('size', 10);
|
|
||||||
|
|
||||||
return $query->paginate($size, ['*'], 'page', $page);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function handleUpload($file)
|
private function handleUpload($file)
|
||||||
{
|
{
|
||||||
$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