Chinh sua giao dien phu hop tailwind css va upload
Some checks failed
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
Tests / PHP 8.5 (push) Has been cancelled

This commit is contained in:
2026-05-05 09:25:28 +00:00
parent 8c6b71cb8a
commit fb1f82e1a0
12 changed files with 834 additions and 466 deletions

View File

@@ -10,12 +10,19 @@ class CreateFeedback extends CreateRecord
{
protected static string $resource = FeedbackResource::class;
protected array $pendingAttachments = [];
protected string $pendingCollection = 'general';
protected function mutateFormDataBeforeCreate(array $data): array
{
if (($data['is_general'] ?? false) === true) {
$data['customer_product_id'] = null;
}
unset($data['is_general'], $data['attachment_collection']);
$this->pendingAttachments = $data['attachments'] ?? [];
$this->pendingCollection = $data['attachment_collection'] ?? 'general';
unset($data['is_general'], $data['attachment_collection'], $data['attachments']);
return $data;
}
@@ -23,8 +30,6 @@ class CreateFeedback extends CreateRecord
protected function afterCreate(): void
{
$feedback = $this->getRecord();
$attachments = $this->data['attachments'] ?? [];
$collection = $this->data['attachment_collection'] ?? 'general';
$feedback->interactions()->create([
'user_id' => auth()->id(),
@@ -33,20 +38,27 @@ class CreateFeedback extends CreateRecord
'changes' => ['status' => ['old' => null, 'new' => $feedback->status]],
]);
if (! empty($attachments)) {
$disk = Storage::disk('local');
foreach ($attachments as $path) {
$feedback->attachments()->create([
'uuid' => (string) \Illuminate\Support\Str::uuid(),
'user_id' => auth()->id(),
'name' => basename($path),
'path' => $path,
'disk' => 'local',
'collection' => $collection,
'mime_type' => $disk->mimeType($path),
'size' => $disk->size($path),
]);
if (empty($this->pendingAttachments)) {
return;
}
$disk = Storage::disk('public');
foreach ($this->pendingAttachments as $path) {
if (! $disk->exists($path)) {
continue;
}
$feedback->attachments()->create([
'uuid' => (string) \Illuminate\Support\Str::uuid(),
'user_id' => auth()->id(),
'name' => basename($path),
'path' => $path,
'disk' => 'public',
'collection' => $this->pendingCollection,
'mime_type' => $disk->mimeType($path),
'size' => $disk->size($path),
]);
}
}
}

View File

@@ -63,7 +63,7 @@ class EditFeedback extends EditRecord
FileUpload::make('transfer_attachments')
->label(__('app.attachments'))
->multiple()
->disk('local')
->disk('public')
->directory('feedback-attachments')
->columnSpanFull(),
])
@@ -82,13 +82,23 @@ class EditFeedback extends EditRecord
);
if (! empty($data['transfer_attachments'])) {
$fileService = App::make(FileService::class);
$fileService->upload(
$data['transfer_attachments'],
'general',
$feedback,
$sender->id,
);
$disk = Storage::disk('public');
foreach ($data['transfer_attachments'] as $path) {
if (! $disk->exists($path)) {
continue;
}
$feedback->attachments()->create([
'uuid' => (string) \Illuminate\Support\Str::uuid(),
'user_id' => $sender->id,
'name' => basename($path),
'path' => $path,
'disk' => 'public',
'collection' => 'general',
'mime_type' => $disk->mimeType($path),
'size' => $disk->size($path),
]);
}
}
Notification::make()
@@ -145,12 +155,19 @@ class EditFeedback extends EditRecord
return view('filament.resources.feedback.edit-footer');
}
protected array $pendingAttachments = [];
protected string $pendingCollection = 'general';
protected function mutateFormDataBeforeSave(array $data): array
{
if (($data['is_general'] ?? false) === true) {
$data['customer_product_id'] = null;
}
unset($data['is_general'], $data['attachment_collection']);
$this->pendingAttachments = $data['attachments'] ?? [];
$this->pendingCollection = $data['attachment_collection'] ?? 'general';
unset($data['is_general'], $data['attachment_collection'], $data['attachments']);
$newStatus = $data['status'] ?? null;
if ($newStatus === 'closed' && $this->getRecord()->status !== 'closed') {
@@ -163,24 +180,28 @@ class EditFeedback extends EditRecord
protected function afterSave(): void
{
$attachments = $this->data['attachments'] ?? [];
$collection = $this->data['attachment_collection'] ?? 'general';
if (empty($this->pendingAttachments)) {
return;
}
if (! empty($attachments)) {
$disk = Storage::disk('local');
$feedback = $this->getRecord();
foreach ($attachments as $path) {
$feedback->attachments()->create([
'uuid' => (string) \Illuminate\Support\Str::uuid(),
'user_id' => auth()->id(),
'name' => basename($path),
'path' => $path,
'disk' => 'local',
'collection' => $collection,
'mime_type' => $disk->mimeType($path),
'size' => $disk->size($path),
]);
$disk = Storage::disk('public');
$feedback = $this->getRecord();
foreach ($this->pendingAttachments as $path) {
if (! $disk->exists($path)) {
continue;
}
$feedback->attachments()->create([
'uuid' => (string) \Illuminate\Support\Str::uuid(),
'user_id' => auth()->id(),
'name' => basename($path),
'path' => $path,
'disk' => 'public',
'collection' => $this->pendingCollection,
'mime_type' => $disk->mimeType($path),
'size' => $disk->size($path),
]);
}
}

View File

@@ -75,7 +75,7 @@ class InteractionsRelationManager extends RelationManager
FileUpload::make('attachments')
->label(__('app.attachments'))
->multiple()
->disk('local')
->disk('public')
->directory('feedback-attachments')
->columnSpanFull(),
]);
@@ -203,15 +203,19 @@ class InteractionsRelationManager extends RelationManager
$attachments = $data['_attachments'] ?? [];
if (! empty($attachments)) {
$disk = Storage::disk('local');
$disk = Storage::disk('public');
foreach ($attachments as $path) {
if (! $disk->exists($path)) {
continue;
}
$record->attachments()->create([
'uuid' => (string) \Illuminate\Support\Str::uuid(),
'feedback_id' => $record->feedback_id,
'user_id' => auth()->id(),
'name' => basename($path),
'path' => $path,
'disk' => 'local',
'disk' => 'public',
'collection' => 'general',
'mime_type' => $disk->mimeType($path),
'size' => $disk->size($path),

View File

@@ -195,10 +195,9 @@ class FeedbackForm
FileUpload::make('attachments')
->label(__('app.files'))
->multiple()
->disk('local')
->disk('public')
->directory('feedback-attachments')
->columnSpan(1)
->dehydrated(false),
->columnSpan(1),
])
->columns(2),
]);

View File

@@ -24,7 +24,7 @@ class FileService
protected int $maxSize = 20480;
protected string $defaultDisk = 'local';
protected string $defaultDisk = 'public';
/**
* Upload files and create FeedbackAttachment records.
@@ -35,7 +35,7 @@ class FileService
Model $model,
int $userId,
?int $interactionId = null,
string $disk = 'local',
string $disk = 'public',
): array {
$records = [];
@@ -71,7 +71,7 @@ class FileService
public function getTemporaryUrl(FeedbackAttachment $attachment, int $minutes = 10): string
{
if ($attachment->disk === 'public') {
return Storage::disk('public')->url($attachment->path);
return asset('storage/' . $attachment->path);
}
return Storage::disk($attachment->disk)->temporaryUrl(