<!-- Source: @site/projects/webhooks-for-laravel/docs/guides/searching-the-logs.md -->
<!-- Canonical: https://docs.pushery.com/webhooks-for-laravel/guides/searching-the-logs/ -->

# Searching the logs

> Full-text search over the delivery and call logs is opt-in and takes three steps past search.enabled: Scout, a searchable model, and a switch for payloads.

The outbound delivery log and the inbound call log can be searched through **Laravel Scout**.
Nothing about it is on by default, and nothing about it is wired for you: `laravel/scout` is a
Composer *suggestion*, not a dependency, and flipping `search.enabled` on its own indexes
nothing at all — silently, because the model the dashboard reads is still the un-indexed one.

Three steps, all required, in this order.

## 1. Install Scout

```bash
composer require laravel/scout
```

Pick the engine in `config/scout.php`, not here — that setting is Scout's. `database` needs no
extra service; `meilisearch` needs a running Meilisearch plus `MEILISEARCH_HOST` and
`MEILISEARCH_KEY`.

## 2. Switch the layer on

```php
// config/webhooks.php
'search' => [
    'enabled' => true,
],
```

While this is `false` the shipped models report `shouldBeSearchable()` as `false`, so no row is
ever written to an index — which is why the flag is safe to leave on in an environment that has
no engine yet.

## 3. Point something searchable at the table

This is the step that has no default, and the reason step 2 alone appears to do nothing.

```php
// config/webhooks.php
'dashboard' => [
    'source_model' => \Pushery\Webhooks\Search\SearchableWebhookDelivery::class,
],
```

`SearchableWebhookDelivery` and `SearchableWebhookCall` are ready-made subclasses that carry the
Scout trait. If you already read the log through a model of your own, apply
`Pushery\Webhooks\Search\SearchableDelivery` or `SearchableCall` to that model instead — the
traits are the same thing without the subclass.

## What is indexed, and what is not

Only queryable, non-sensitive fields, and **the payload is not among them by default**. Both
logs index the event type, the status and the timestamp. What differs is the field each one is
scoped by, because the two logs answer to different owners:

- **Outbound deliveries** carry the tenant: `owner_type` *and* `owner_id`, the whole morph pair,
  so two tenants sharing an id under different owner types are not conflated. The endpoint `url`
  is indexed as well, without its userinfo and query, where hosts put credentials. Scope a query
  with `searchForOwner($ownerType, $ownerId, $query)`.
- **Inbound calls** carry the producer instead: `source`. There is no owner or tenant column on
  this log at all, so a tenant-scoped query has nothing to filter on here. Scope a query with
  `searchForSource($source, $query)`.

### The payload, and the fourth step you have to take on purpose

`search.index_payload` is a separate switch and it is `false`. Until you set it, no part of a
body reaches the index — which is why a search for something you can read on screen finds
nothing, and why nothing about that is broken.

```php
// config/webhooks.php
'search' => [
    'index_payload' => true,                 // WEBHOOKS_SEARCH_INDEX_PAYLOAD
    'payload_excerpt_chars' => 500,          // the cap once it is on
],
```

Turn it on only where the index is as protected as the database it mirrors, and read
[Security](https://docs.pushery.com/webhooks-for-laravel/security.md) first — the warning below is the whole reason this is a second
switch rather than part of the first.

A payload offloaded to a Storage disk is **never** indexed verbatim even then — its excerpt is
left empty, so a large body is not copied into the index.

:::warning An index is not a screen
On every screen the payload is governed per request by the `view-webhook-payload` ability. An
index has no such request and no such reader, so anything copied into it is readable by anyone
who can query the engine — which is why `index_payload` is off and is the one setting on this
page you should have a reason for. With it on, keep the excerpt short. Either way, constrain
every query by the scoping field of the log you are querying — the owner pair outbound, the
source inbound. The two shipped helpers named above do exactly that.
:::
