diff --git a/app/Livewire/Tickets/Create.php b/app/Livewire/Tickets/Create.php index e333590f2..064e5e0ce 100644 --- a/app/Livewire/Tickets/Create.php +++ b/app/Livewire/Tickets/Create.php @@ -8,19 +8,37 @@ use App\Models\Ticket; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\RateLimiter; use Illuminate\Support\Facades\Storage; +use Livewire\WithFileUploads; #[DisabledIf('tickets_disabled')] class Create extends Component { - public string $message; + use WithFileUploads; - public string $subject; + public string $message = ''; - public string $department; + public string $subject = ''; + + public string $department = ''; public ?int $service = null; - public string $priority; + public string $priority = ''; + + public array $attachments = []; + + public function updatedAttachments() + { + $this->validate([ + 'attachments.*' => 'image|max:5120', // 5MB max per image + ]); + } + + public function removeAttachment($index) + { + unset($this->attachments[$index]); + $this->attachments = array_values($this->attachments); + } public function create() { @@ -31,6 +49,7 @@ class Create extends Component 'subject' => 'required|string', 'message' => 'required|string', 'priority' => 'required|in:low,medium,high', + 'attachments.*' => 'image|max:5120', ]); if (RateLimiter::tooManyAttempts('create-ticket', 1)) { @@ -41,6 +60,19 @@ class Create extends Component RateLimiter::increment('create-ticket', 30); + // Handle attachments + $attachmentData = []; + if (!empty($this->attachments)) { + foreach ($this->attachments as $attachment) { + $path = $attachment->store('ticket-attachments', 'public'); + $attachmentData[] = [ + 'path' => $path, + 'name' => $attachment->getClientOriginalName(), + 'url' => Storage::url($path), + ]; + } + } + $ticket = Ticket::create([ 'user_id' => Auth::id(), 'department' => $this->department, @@ -52,11 +84,13 @@ class Create extends Component $ticket->messages()->create([ 'user_id' => Auth::id(), 'message' => $this->message, + 'attachments' => !empty($attachmentData) ? $attachmentData : null, ]); $this->notify('Message sent successfully'); $this->message = ''; + $this->attachments = []; $this->dispatch('saved'); $this->redirect(route('tickets.show', $ticket), true); diff --git a/themes/lucentui/views/tickets/create.blade.php b/themes/lucentui/views/tickets/create.blade.php index 712b0594d..33d4238d7 100644 --- a/themes/lucentui/views/tickets/create.blade.php +++ b/themes/lucentui/views/tickets/create.blade.php @@ -50,6 +50,57 @@ + + +
+ + +
+ +
+ + +
+
+ + {{ __('ticket.uploading') ?? 'Uploading...' }} +
+
+ + + @if(count($attachments) > 0) +
+ @foreach($attachments as $index => $attachment) +
+
+ Preview +
+ +

{{ $attachment->getClientOriginalName() }}

+
+ @endforeach +
+ @endif + + @error('attachments.*') +

{{ $message }}

+ @enderror +