Filament Terms Guard

Filament Terms Guard

Documentation for the Filament Terms Guard plugin: create, publish, and version terms and conditions across multi-tenant panels and multiple auth guards, with automatic consent redirects when a new version goes live.

Filament v3 Filament v4 Filament v5

Filament Terms Guard manages terms and conditions across your panels: create, update, publish, and duplicate them, and keep users up to date automatically. It works with multi-tenant panels and multiple auth guards.

Filament Terms Guard plugin - Consent user view screenshot

Key features

  • Create terms and conditions through an admin interface, no manual content management needed.
  • Publish a new version to make it live.
  • Duplicate an existing version as a starting point for the next one.
  • Automatic redirection: once a new version is published on a panel where the plugin is active, every connected user is redirected to a consent page before they can continue.

Usage

  • Manage terms and conditions from the dedicated section in your admin panel.
  • Create a new version, or duplicate an existing one, scoped to a specific panel.
  • Publish it. Every user connected to that panel gets redirected to validate the new terms before continuing.

Installation

Add the plugin's private repository to composer.json:

{
    "repositories": [
        {
            "type": "composer",
            "url": "https://filament-terms-guard.composer.sh"
        }
    ]
}

Compatibility: Filament v4 and v5 are supported from version 2.x. Filament v3 is supported on version 1.x.

composer require yebor974/filament-terms-guard

Composer will prompt for credentials: your email as the username, and your license key followed by : and the domain being activated as the password.

Loading composer repositories with package information
Authentication required (filament-terms-guard.composer.sh):
Username: [email protected]
Password: 8c21df8f-6273-4932-b4ba-8bcc723ef500:domain.tld

Settings

php artisan vendor:publish --tag="filament-terms-guard-migrations"
php artisan migrate

Config, translations, and views can be published separately if you need to customize them:

php artisan vendor:publish --tag="filament-terms-guard-config"
php artisan vendor:publish --tag="filament-terms-guard-translations"
php artisan vendor:publish --tag="filament-terms-guard-views"

In your .env file, list which panels should require consent, comma-separated:

TERMS_GUARD_PANELS=admin,customer

A panel not listed here never asks for consent. Removing a panel's ID from this list is how you disable it for that panel.

Wiring it up

Register the plugin on any panel where users should be asked for consent:

use Yebor974\FilamentTermsGuard\TermsGuardPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            TermsGuardPlugin::make()
        ]);
}

On the panel where terms should also be managed (created, published, duplicated):

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            TermsGuardPlugin::make()
                ->termsResource()
        ]);
}

Implement TermsGuardContract on your authentication model. The default HasTermsGuard trait covers the standard case:

use Yebor974\FilamentTermsGuard\Contracts\TermsGuardContract;
use Yebor974\FilamentTermsGuard\Traits\HasTermsGuard;

class User extends Authenticatable implements TermsGuardContract
{
    use HasTermsGuard;
}

For custom consent criteria, implement needAcceptNewTerms() (and the terms() relation) yourself instead of using the trait:

class User extends Authenticatable implements TermsGuardContract
{
    public function terms(): MorphToMany
    {
        return $this->morphToMany(Term::class, 'model', TermConsent::class)
            ->withTimestamps();
    }

    public function needAcceptNewTerms(): bool
    {
        $panel ??= Filament::getCurrentPanel();
        $currentTerm = Term::getCurrentTerm($panel->getId());

        return $currentTerm && !$this->terms()->find($currentTerm);
    }
}

Authorization

Secure the Terms resource with a policy. A stub is provided as a starting point; register it explicitly:

use App\Policies\TermPolicy;
use Yebor974\FilamentTermsGuard\Models\Term;

protected $policies = [
    Term::class => TermPolicy::class,
];

Tips

Panel IDs shown in selects and labels can be translated after publishing the translation files:

'panels' => [
    'admin' => 'Admin Panel',
    'super-admin' => 'Super Admin Panel',
],

To remove the navigation group for the Terms resource, set it to an empty string:

'terms' => [
    'navigation' => [
        'group' => '',
    ],
],

To retrieve the currently active terms for a panel from anywhere in your code:

use Filament\Facades\Filament;
use Yebor974\FilamentTermsGuard\Models\Term;

$panel ??= Filament::getCurrentPanel();
$currentTerm = Term::getCurrentTerm($panel->getId());

Returns null if the panel isn't listed in TERMS_GUARD_PANELS.

Screenshots

Filament Terms Guard plugin - User consent view for new terms and conditions
User consent view for new terms and conditions
Filament Terms Guard Plugin - List
List all versions
Filament Terms Guard Plugin - Creating new terms
Creating new terms
Filament Terms Guard Plugin - View of a terms and conditions and associated consents
View of a terms and conditions and associated consents

Changelog

See the changelog for recent changes.

Support

Security issues or support requests: [email protected]

License options

  • Annual Single Project: all features, updates and support for one year, up to three environments (local, staging, production).
  • Annual Unlimited Projects: same as above, unlimited environment activations.
  • Lifetime Unlimited Projects: lifetime access, unlimited environment activations.

Full terms on the license page.

Did this guide save you time? Keeping the site online has a cost, and a one-time donation helps cover the server. Completely optional.

Buy me a coffee →