# Acceptance and re-acceptance

For private visitor links and the optional Customer Portal feed, see [Let people accept for themselves](overview.md#let-people-accept-for-themselves).

## Require acceptance before continuing

The package registers the `document.acceptance` middleware alias. Add it after `web` and your authentication middleware to the route or group you want to protect. It does not attach itself to all web or admin routes. Enable it in `config/capell-document-lifecycle.php` (publish with `php artisan vendor:publish --tag=capell-document-lifecycle-config`):

```php
return [
    'reacceptance' => [
        'enabled' => true,
        'guard' => null, // Default guard, or your customer guard name.
        'documents' => ['customer_terms'], // Exact registered document keys.
        'routes' => ['account.*'],
        'paths' => [], // Alternatively: ['members/*'].
    ],
];
```

```php
Route::middleware(['web', 'auth', 'document.acceptance'])
    ->prefix('account')->as('account.')
    ->group(function (): void {
        Route::get('/', AccountController::class)->name('show');
    });
```

Route-name and request-path patterns are alternatives: either match selects the request. Empty lists select nothing. The guard must identify the same Eloquent user as the protected area; guests and non-Eloquent identities pass through. Guest acceptance remains the explicit person-bound signed-link flow above. Keep login, logout, account recovery and the acceptance page outside protected areas.

For each configured active document with a publication, `ResolveRequiredDocumentAcceptanceAction` calls `RequiresDocumentReAcceptanceAction` for the signed-in user. Missing, draft, archived and unpublished documents are ignored. A first acceptance is required too. Pending documents are presented one at a time in configured order. Self-acceptances from sign-up with no separate subject count, as do acceptances whose subject is the user. An acceptance made for a different subject does not count.

The gate redirects to the stock signed acceptance page before running the protected handler. Its encrypted payload binds the link to the guard selected when the gate issued it. On submission, that guard must still identify the same user. Switching accounts or signing out refuses acceptance with a translated message and records nothing. The person must tick the confirmation for the current version; recording uses `AcceptDocumentFromLinkAction` and the existing `RecordDocumentAcceptanceAction`.

Gate links carry a signed local continuation path, including the query string. After acceptance the person returns there with a GET request, and any other pending document is checked. Protected writes also carry a signed interruption flag. The acceptance page explains that the change was not saved and must be submitted again after accepting the required documents. After acceptance, the same notice is included in the `capell_document_acceptance_status` session flash; display this flash in the protected area's layout so the person sees it on returning. The middleware never stores or replays the original request body. Make sure protected write URLs have a suitable GET continuation page.

The enabled flag disables only this gate; explicitly issued signed acceptance links and the optional Customer Portal feed remain available.

The package does not dispatch invitations or infer an audience. Document keys are installation-wide; configure the routes and guard for the intended audience. Explicit visitor links remain bearer links for the named person and do not require a signed-in account: keep them private. Gate links additionally require the original signed-in identity. No staff permissions or Customer Portal installation are required to use the acceptance page.