# Laravel SDK

Install dimmi/dimmi-laravel for Blade messenger rendering, automatic identity signing, the Dimmi facade, and webhook routes.

`dimmi/dimmi-laravel` supports Laravel 10, 11, and 12 on PHP 8.2+ and includes the [PHP SDK](/developers/sdks/php/).

```bash
composer require dimmi/dimmi-laravel
php artisan dimmi:install
```

`dimmi:install` publishes `config/dimmi.php` and adds these keys to `.env` and `.env.example`:

```bash title=".env"
DIMMI_BASE_URL=https://trydimmi.com
DIMMI_TOKEN=<api_token>
DIMMI_WORKSPACE=
DIMMI_APP_ID=wgt_<app_id>
DIMMI_IDENTITY_SECRET=dmi_idsec_<secret>
DIMMI_IDENTITY_KID=isk_<key_id>
DIMMI_WEBHOOK_SECRET=whsec_<secret>
```

| Environment key | Purpose |
| --- | --- |
| `DIMMI_BASE_URL` | Your dimmi URL (change when self-hosting). |
| `DIMMI_TOKEN` | Your [API token](/developers/api/authentication/). |
| `DIMMI_WORKSPACE` | Leave blank; tokens already scope to their workspace. |
| `DIMMI_APP_ID` | Messenger app ID (`wgt_...`) from **Settings → Messengers**. |
| `DIMMI_IDENTITY_SECRET`, `DIMMI_IDENTITY_KID` | Secret from [identity verification](/developers/messenger/identity-verification/). |
| `DIMMI_WEBHOOK_SECRET` | Signing secret for your [webhook endpoint](/developers/webhooks/verify-signatures/). |

Run `php artisan dimmi:test` to verify your config. It checks API connectivity, signs a sample identity token, and exits non-zero if anything fails.

## Render the messenger in Blade

```blade title="resources/views/layouts/app.blade.php"
    @dimmiMessenger
</body>
```

`@dimmiMessenger` signs an identity token for `auth()->user()` automatically and falls back to anonymous chat for guests. By default it sends the user's `id`, `email`, `name`, `email_verified_at`, and `created_at`.

| Goal | Config setting |
| --- | --- |
| Send extra user attributes | `'user' => ['attributes' => ['plan', 'team_name' => 'team.name']]` in `config/dimmi.php` |
| Build a custom identity payload | `'user' => ['resolver' => App\Support\DimmiIdentity::class]` (invokable class returning an array) |
| Fetch tokens from built-in `GET /dimmi/token` | `DIMMI_MESSENGER_IDENTITY=url` |

## Call the REST API

Use the `Dimmi` facade to call any method from the PHP SDK:

```php title="app/Listeners/SyncCustomer.php"
<?php

namespace App\Listeners;

use Dimmi\Laravel\Facades\Dimmi;
use Illuminate\Auth\Events\Registered;

class SyncCustomer
{
    public function handle(Registered $event): void
    {
        Dimmi::contacts()->store([
            'email' => $event->user->email,
            'external_id' => (string) $event->user->id,
        ]);
    }
}
```

## Receive webhooks

Add `Route::dimmiWebhooks('webhooks/dimmi')` in `routes/web.php`. The route verifies every signature, rejects unsigned requests with `400`, and dispatches two Laravel events:

- **`Dimmi\Laravel\Events\DimmiWebhookReceived`:** fires on every webhook, with the parsed event on `$received->event`.
- **`dimmi.webhook.<type>`:** fires per event type (such as `dimmi.webhook.conversation.created`) with a `Dimmi\WebhookEvent`.

See [Verify webhook signatures](/developers/webhooks/verify-signatures/) for a ready-to-paste event listener.

---

Index of all dimmi docs: https://trydimmi.com/llms.txt (full text: https://trydimmi.com/llms-full.txt)
