refactor: memperbaiki fitur yang ada upload attachementnya

This commit is contained in:
Yoga Pangestu 2024-11-30 22:56:55 +07:00
parent 8d7d455a7b
commit 36408541c5
5 changed files with 13 additions and 8 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');k
$this->uploadAttachment($validatedData['proof'], 'expenses', Expense::class, $expense->id, 'expenses');
}
});

View File

@ -34,7 +34,7 @@ public function create(): View
{
return view('pages.admin.finance.payroll.create', [
'pageTitle' => 'Tambah Gaji',
'employees' => User::query()->barbershop()->latest()->get(),
'employees' => User::with('biography')->barbershop()->latest()->get(),
]);
}
@ -63,7 +63,7 @@ public function edit(Payroll $payroll): View
{
return view('pages.admin.finance.payroll.edit', [
'pageTitle' => 'Edit Gaji',
'employees' => User::query()->barbershop()->latest()->get(),
'employees' => User::with('biography')->barbershop()->latest()->get(),
'payroll' => $payroll,
]);
}

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 '-';

View File

@ -99,6 +99,11 @@ public function cash(): HasMany
return $this->hasMany(Cash::class);
}
public function debts(): HasMany
{
return $this->hasMany(Debt::class);
}
public function attachments(): MorphMany
{
return $this->morphMany(Attachment::class, 'attachmentable');

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