51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Livewire\Whatsapp;
|
|
|
|
use App\Models\WhatsappWebhookLog;
|
|
use Livewire\Component;
|
|
use Livewire\WithPagination;
|
|
|
|
class ShowLogsWebhook extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
public string $search = '';
|
|
public ?int $viewId = null;
|
|
public ?string $viewPayload = null;
|
|
|
|
public function viewLog(int $id): void
|
|
{
|
|
$log = WhatsappWebhookLog::findOrFail($id);
|
|
$this->viewId = $id;
|
|
$decoded = json_decode($log->payload, true);
|
|
$this->viewPayload = json_encode($decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
|
}
|
|
|
|
public function clearView(): void
|
|
{
|
|
$this->viewId = null;
|
|
$this->viewPayload = null;
|
|
}
|
|
|
|
public function deleteLog(int $id): void
|
|
{
|
|
WhatsappWebhookLog::findOrFail($id)->delete();
|
|
}
|
|
|
|
public function clearAll(): void
|
|
{
|
|
WhatsappWebhookLog::truncate();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$logs = WhatsappWebhookLog::when($this->search, fn($q) =>
|
|
$q->where('payload', 'like', "%{$this->search}%"))
|
|
->orderByDesc('created_at')
|
|
->paginate(25);
|
|
|
|
return view('livewire.whatsapp.show-logs-webhook', compact('logs'));
|
|
}
|
|
}
|