requireCustomer(); if ($customer === null) { return $this->closeModal(); } $data = $this->validate([ 'category' => ['required', Rule::in(SupportRequest::CATEGORIES)], 'subject' => 'required|string|min:3|max:150', 'body' => 'required|string|min:10|max:5000', ]); $instance = $customer->instances() ->whereIn('status', ['active', 'cancellation_scheduled']) ->latest('id') ->first() ?? $customer->instances()->latest('id')->first(); SupportRequest::create([ 'customer_id' => $customer->id, 'instance_id' => $instance?->id, 'subject' => $data['subject'], 'category' => $data['category'], 'body' => $data['body'], 'status' => 'open', // The person, not the account: on a shared login the account name // says nothing about who is actually asking. 'reported_by' => auth()->user()?->name ?: auth()->user()?->email, ]); $this->dispatch('notify', message: __('support.sent')); return $this->redirectRoute('support', navigate: true); } public function render() { return view('livewire.new-support-request', [ 'categories' => SupportRequest::CATEGORIES, ]); } }