Chinh sua giao dien phu hop tailwind css va upload
This commit is contained in:
@@ -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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user