fix(attachment): memperbaiki argumen upload attachment

This commit is contained in:
Yoga Pangestu 2024-11-30 21:13:11 +07:00
parent 4fc0a06061
commit f064f4da8f
5 changed files with 11 additions and 11 deletions

View File

@ -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
}
});

View File

@ -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 '<a href="'.$imageUrl.'" ><img src="'.$imageUrl.'" alt="Check-in Image" height="77" width="77"></a>';
return '<a href="' . $imageUrl . '" ><img src="' . $imageUrl . '" alt="Check-in Image" height="77" width="77"></a>';
}
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 '<a href="'.$imageUrl.'" ><img src="'.$imageUrl.'" alt="Check-out Image" height="77" width="77"></a>';
return '<a href="' . $imageUrl . '" ><img src="' . $imageUrl . '" alt="Check-out Image" height="77" width="77"></a>';
}
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([

View File

@ -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');
}
});

View File

@ -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');
}
});

View File

@ -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(
[