# DataTable CSV export and Laravel Reverb

Maestro CORE exposes async CSV export for server-driven B2CDataTable resources (`POST /api/datatables/{resourceKey}/export`). Finished files trigger a `DataTableExportReady` broadcast on the private channel `user.notifications.{userId}` so the SPA can show the topbar downloads list (see `useRealtimeNotifications`).

## Host application checklist

1. **Composer**  
   The package requires `laravel/reverb` (declared in `@maestro/core` `composer.json`). Run `composer update` in the consuming app.

2. **Queue**  
   Process the `exports` queue (e.g. `php artisan queue:work --queue=exports`). Exports are dispatched with `onQueue('exports')`.

3. **Filesystem disk `exports`**  
   Add to `config/filesystems.php`:

   ```php
   'exports' => [
       'driver' => 'local',
       'root' => storage_path('app/exports/datatables'),
       'throw' => false,
   ],
   ```

   Ensure `storage/app/exports/datatables` exists and is writable.

4. **Broadcasting**  
   - Set `BROADCAST_CONNECTION=reverb` and the `REVERB_*` / `VITE_REVERB_*` variables (see Laravel Reverb docs).
   - Register a private channel authorization for `user.notifications.{userId}` in `routes/channels.php`, for example:

   ```php
   use Illuminate\Support\Facades\Broadcast;

   Broadcast::channel('user.notifications.{userId}', function ($user, $userId) {
       return (int) $user->id === (int) $userId;
   });
   ```

   Wire `channels.php` from your `bootstrap/app.php` (or equivalent) per Laravel 11+ convention.

5. **SPA env**  
   In the Vite app, set `VITE_REVERB_APP_KEY`, `VITE_REVERB_HOST`, `VITE_REVERB_PORT`, and `VITE_REVERB_SCHEME` to match the Reverb server.

6. **Config publish (optional)**  
   `php artisan vendor:publish --tag=core-config` copies `datatable.php` (export TTL: `DATATABLE_EXPORT_TTL_MINUTES`).

7. **Translations**  
   Column and resource labels live under `vendor/maestro/core/lang` and are loaded with the `maestro` namespace (`maestro::datatable.*`).

