53 lines
1.7 KiB
PHP
53 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Feedback\Pages;
|
|
|
|
use App\Filament\Resources\Feedback\FeedbackResource;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class CreateFeedback extends CreateRecord
|
|
{
|
|
protected static string $resource = FeedbackResource::class;
|
|
|
|
protected function mutateFormDataBeforeCreate(array $data): array
|
|
{
|
|
if (($data['is_general'] ?? false) === true) {
|
|
$data['customer_product_id'] = null;
|
|
}
|
|
unset($data['is_general'], $data['attachment_collection']);
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function afterCreate(): void
|
|
{
|
|
$feedback = $this->getRecord();
|
|
$attachments = $this->data['attachments'] ?? [];
|
|
$collection = $this->data['attachment_collection'] ?? 'general';
|
|
|
|
$feedback->interactions()->create([
|
|
'user_id' => auth()->id(),
|
|
'type' => 'note',
|
|
'content' => __('feedback.created_via', ['channel' => $feedback->feedbackChannel?->name ?? __('feedback.unknown_channel')]),
|
|
'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),
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|