File: /var/www/admin.fixgini.com/app/Livewire/Support/Index.php
<?php
namespace App\Livewire\Support;
use Livewire\Component;
use Livewire\WithPagination;
use App\Models\SupportMail;
class Index extends Component
{
use WithPagination;
public $search = ''; // Search property
protected $queryString = ['search']; // Optional: retain the search query in the URL
public function updatingSearch()
{
$this->resetPage(); // Reset pagination when search input changes
}
public function changeSupportStatus($supportId, $status)
{
// Find the support mail record by ID
$support = SupportMail::find($supportId);
if ($support) {
// Update the status
$support->update(['status' => $status]);
// Optionally, you can add a success message or emit an event
session()->flash('message', 'Support status updated successfully.');
} else {
// If the record is not found
session()->flash('error', 'Support mail not found.');
}
}
public $ticketId;
public $replyMessage;
public $support;
public $subject;
public $message;
// Prepare the reply by setting the ticket ID
public function prepareReply($id)
{
$this->support = SupportMail::where('ticket_no', $id)->first();
$this->subject = $this->support->subject;
$this->message = $this->support->message;
$this->ticketId = $id;
$this->replyMessage = ''; // Clear the reply textarea
}
// Send the reply and save it as a new instance
public function sendReply()
{
$this->validate([
'replyMessage' => 'required|min:5|max:1000',
]);
$support = SupportMail::where('ticket_no', $this->ticketId)->first();
// Save the reply as a new instance
SupportMail::create([
'ticket_no' => $this->ticketId,
'message' => $this->replyMessage,
'subject' => 'RE: '. $support->subject,
'user_id' => $support->user_id,
'status' => 'open',
]);
session()->flash('message', 'Reply sent successfully.');
$this->redirect('/support/ticket');
}
public function render()
{
$supports = SupportMail::with('user')
->where(function ($query) {
$query->where('subject', 'like', '%' . $this->search . '%')
->orWhere('message', 'like', '%' . $this->search . '%')
->orWhereHas('user', function ($userQuery) {
$userQuery->where('name', 'like', '%' . $this->search . '%');
})
->orWhere('ticket_no', 'like', '%' . $this->search . '%');
})
->latest()
->paginate(10);
return view('livewire.support.index', compact('supports'));
}
}