From f064f4da8fd3492961470bf70033dc75d9eada4a Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Sat, 30 Nov 2024 21:13:11 +0700 Subject: [PATCH] fix(attachment): memperbaiki argumen upload attachment --- app/Http/Controllers/Admin/Finance/ExpenseController.php | 2 +- app/Http/Controllers/Admin/Manage/AttendanceController.php | 6 +++--- app/Http/Controllers/Admin/Manage/InventoryController.php | 4 ++-- app/Http/Controllers/Admin/Master/BarbershopController.php | 4 ++-- app/Traits/UploadAttachment.php | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Admin/Finance/ExpenseController.php b/app/Http/Controllers/Admin/Finance/ExpenseController.php index 90ee3b1..805bf92 100644 --- a/app/Http/Controllers/Admin/Finance/ExpenseController.php +++ b/app/Http/Controllers/Admin/Finance/ExpenseController.php @@ -88,7 +88,7 @@ public function update(ExpenseRequest $request, Expense $expense): RedirectRespo } if (isset($validatedData['proof'])) { - $this->uploadAttachment($validatedData['proof'], 'expenses', Expense::class, $expense->id, 'expenses'); + $this->uploadAttachment($validatedData['proof'], 'expenses', Expense::class, $expense->id, 'expenses');k } }); diff --git a/app/Http/Controllers/Admin/Manage/AttendanceController.php b/app/Http/Controllers/Admin/Manage/AttendanceController.php index e9efcdd..7c906b9 100644 --- a/app/Http/Controllers/Admin/Manage/AttendanceController.php +++ b/app/Http/Controllers/Admin/Manage/AttendanceController.php @@ -63,7 +63,7 @@ public function index(Request $request): View|JsonResponse if ($item->check_in) { $imageUrl = Storage::url("attendances/{$item->attachments->first()->formatted_attachment}"); - return 'Check-in Image'; + return 'Check-in Image'; } return '-'; @@ -72,7 +72,7 @@ public function index(Request $request): View|JsonResponse if ($item->check_out) { $imageUrl = Storage::url("attendances/{$item->attachments()->latest()->first()->formatted_attachment}"); - return 'Check-out Image'; + return 'Check-out Image'; } return '-'; @@ -106,7 +106,7 @@ public function store(AttendanceRequest $request): JsonResponse ]); } - $this->uploadAttachment($validatedData['image'], 'attendances', Attendance::class, $newAttendance->id); + $this->uploadAttachment($validatedData['image'], 'attendances', Attendance::class, $newAttendance->id, 'attendance'); }); return response()->json([ diff --git a/app/Http/Controllers/Admin/Manage/InventoryController.php b/app/Http/Controllers/Admin/Manage/InventoryController.php index 3474a1d..e62d6c6 100644 --- a/app/Http/Controllers/Admin/Manage/InventoryController.php +++ b/app/Http/Controllers/Admin/Manage/InventoryController.php @@ -36,7 +36,7 @@ public function store(InventoryRequest $request): RedirectResponse 'user_id' => Auth::id(), 'barbershop_id' => Auth::user()->barbershop_id, ])); - $this->uploadAttachment($validatedData['image'], 'inventory', Inventory::class, $newInventory->id); + $this->uploadAttachment($validatedData['image'], 'inventory', Inventory::class, $newInventory->id, 'inventory'); }); notify()->success('Data berhasil ditambahkan', 'Berhasil'); @@ -51,7 +51,7 @@ public function update(Inventory $inventory, InventoryRequest $request): Redirec $inventory->update($validatedData); if (isset($validatedData['image'])) { - $this->uploadAttachment($validatedData['image'], 'inventory', Inventory::class, $inventory->id); + $this->uploadAttachment($validatedData['image'], 'inventory', Inventory::class, $inventory->id, 'inventory'); } }); diff --git a/app/Http/Controllers/Admin/Master/BarbershopController.php b/app/Http/Controllers/Admin/Master/BarbershopController.php index f03c523..c756c3b 100644 --- a/app/Http/Controllers/Admin/Master/BarbershopController.php +++ b/app/Http/Controllers/Admin/Master/BarbershopController.php @@ -36,7 +36,7 @@ public function store(BarbershopRequest $request): RedirectResponse DB::transaction(function () use ($validatedData) { $newBarbershop = Barbershop::create($validatedData); - $this->uploadAttachment($validatedData['image'], 'barbershop', Barbershop::class, $newBarbershop->id); + $this->uploadAttachment($validatedData['image'], 'barbershop', Barbershop::class, $newBarbershop->id, 'barbeshop'); }); notify()->success('Data berhasil ditambahkan', 'Berhasil'); @@ -59,7 +59,7 @@ public function update(Barbershop $barbershop, BarbershopRequest $request): Redi DB::transaction(function () use ($barbershop, $validatedData) { $barbershop->update($validatedData); if (isset($validatedData['image'])) { - $this->uploadAttachment($validatedData['image'], 'barbershop', Barbershop::class, $barbershop->id); + $this->uploadAttachment($validatedData['image'], 'barbershop', Barbershop::class, $barbershop->id, 'barbershop'); } }); diff --git a/app/Traits/UploadAttachment.php b/app/Traits/UploadAttachment.php index cab8243..4638236 100644 --- a/app/Traits/UploadAttachment.php +++ b/app/Traits/UploadAttachment.php @@ -18,10 +18,10 @@ public function uploadAttachment(UploadedFile|string $file, string $path, string $image = base64_decode($imageData); $extension = 'png'; $fileName = Str::uuid(); - $fullFileName = $fileName.'.'.$extension; + $fullFileName = $fileName . '.' . $extension; $date = now()->format('Y-m-d'); - Storage::disk('public')->put($path.'/'.$date.'/'.$fullFileName, $image); + Storage::disk('public')->put($path . '/' . $date . '/' . $fullFileName, $image); Attachment::updateOrCreate( [ @@ -39,7 +39,7 @@ public function uploadAttachment(UploadedFile|string $file, string $path, string $date = now()->format('Y-m-d'); $extension = $file->getClientOriginalExtension(); $fileName = Str::uuid(); - $file->storeAs($path.'/'.$date, $fileName.'.'.$extension, 'public'); + $file->storeAs($path . '/' . $date, $fileName . '.' . $extension, 'public'); Attachment::updateOrCreate( [