e2d2-dev / betta-terms
Comprehensive Terms Solution with panel/model and management solution
Requires
- filament/filament: ^4.0|^5.0
README
# Terms & Conditions ManagementFor Filament 4.x / 5.0
Features
-
📦 Panel Guard
-
📄 Model Guard
-
🔍 Entity discovery (panel & models)
-
🌐 Localized
-
🎨 Intuitive & Responsive UI
Installation
1. Install Package
composer require e2d2-dev/betta-terms
2. Run Setup Command
Run the setup command
php artisan terms:setup
This will publish migrations, ask to publish the config file and translations
3. Setup User Model
To perform consent on conditions add the HasConsents trait & the CanConsent interface to your auth provider model:
use Betta\Terms\Traits\User\HasConsents; use \Betta\Terms\Contracts\CanConsent; class User extends Authenticatable implements CanConsent { use HasConsents; }
4. Manage Terms Plugin
Add the ManageTermsPlugin to your panel:
use Betta\Terms\ManageTermsPlugin; public static function register(Panel $panel): Panel { $panel->plugins([ ManageTermsPlugin::make(), ]); }
5. Terms Guard Plugin
Add the TermsGuardPlugin plugin to the panel you want to guard:
use Betta\Terms\TermsGuardPlugin; public static function register(Panel $panel): Panel { $panel->plugins([ TermsGuardPlugin::make(), ]); }
6. Panel Registration Form
If you want to have the conditions on your registrations form, add the Register component to your panel.
use Betta\Terms\Filament\Auth\Register; public static function register(Panel $panel): Panel { $panel->registration(Register::class); }
Guards
Guard Features
Every guard can have multiple conditions
Conditions can be:
- skippable -> not required
- persistent -> will need consent every time / multiple times
- orderable
Panel Guard
Terms comes with a multi-panel guard. Each can have an own. The panel guard will be checked for new conditions every login, if there are any new users need to apply to them if not skippable. This includes replaced conditions.
Panel Guard Usage
- Make sure to add the ManageTermsPlugin to your panel
- Create at least one condition
- Create a guard with the
paneloption - Link them together
Modify Panel Slug Generation
Hook into the Panel slug creation using:
use Betta\Terms\Terms; public function boot(): void { Terms::generatePanelSlugUsing(fn(string $panel) => generate_slug($panel)) }
You can also just change the panel slug prefix in the config.
'config/betta-terms.php' 'slug' => [ 'panel' => [ 'prefix' => 'panel//', ], ],
Model Guard
Some records may need conditions (e.g. invoices & registrations). The model guard provides a solution for that.
Consents will be stored in the record and only committed when commitConsent() is called (e.g. after successful process).
Model Guard Setup
Add the HasGuardConditions trait to your order model:
use Betta\Terms\Traits\Model\HasGuardConditions; use Betta\Terms\Contracts\ModelConditions; class YourModel implements ModelConditions { use HasGuardConditions; }
Add the ConsentComponent to your form schema:
use Betta\Terms\Filament\Forms\ConsentComponent; public function form(Schema $schema): Schema { return $schema ->components([ ConsentComponent::make() ->compact(), ]); }
Add A Model Guard in the GuardResource
Add a guard in the GuardResource by selecting the type model. Models from App\Models namespace will be auto listed.
Add conditions to that model.
Register Models
You can add more models to the select by registering them
use Betta\Terms\ManageTermsPlugin; public static function register(Panel $panel): Panel { $panel->plugins([ ManageTermsPlugin::make() ->registerModel(string $model, ?string $name), ]); }
Hook into Model Slug Creation
You can change how the slug is generated by providing a closure to Terms in a service provider:
use Betta\Terms\Terms; public function boot(): void { Terms::generateModelSlugUsing(fn(string $class) => generate_slug($class)) }
You can also just change the model slug prefix in the config.
'config/betta-terms.php' 'slug' => [ 'model' => [ 'prefix' => 'model//', ], ],
Conditions
Condition Guards
- Every Condition can be added to any guard.
- Conditions can be marked active or skippable in each guard separately
- Conditions can be activated as soon as they have data filled in
Condition Name
The name is required. It will show up to the client. It is visible as the checkbox label in the compact mode and as section heading in the full mode
Condition Description
Description is not required but can be a useful info for clients for further context.
It will show up in compact mode below the accepted checkbox and as description in full mode.
Condition Slug
The slug is autogenerated with timestamp as prefix and with revision suffix.
Condition Source
Every condition has its own content which can be supplied as
- text (url+markdown)
- file (with upload)
- as url or just the name for small consents.
Condition Source Options
- Link
- Text
- Markdown
- Iframe
- Simple
- Image
Condition Replacement
When a condition needs improvement, you can't just edit the file, because it is an official document. Hit the replace action in the ConditionResource to replace it. As soon as all required data is filled in, you will be asked to replace the predecessor (previous version). The Predecessor will be removed from all guards and replaced by the successor.
Remove Conditions
A Condition can only be deleted when they have any consents yet.
Condition Consents
Every user's consent will be stored. On which guard or component it was signed will also be stored in the signed_on column of the consent table
ConsentComponent
Visual Modes
The consent component has two visual modes: regular and compact. Regular mode is of bigger size for full-page usage. Compact mode for in-form usage.
Regular Mode
Compact Mode
Every condition is presented with the AcceptedCheckbox which has the condition name as label, description as hint and
a view action to display the content if applicable.
use Betta\Terms\Filament\Forms\ConsentComponent; ConsentComponent::make() ->compact(),
Consent Component Layouts
The component does support further layouts:
use Betta\Terms\Filament\Forms\ConsentComponent; ConsentComponent::make() ->aside() ->asSection(),
Guards
The consent component will find its guards automagically, but you can also specify the guard by slug or by model
use Betta\Terms\Filament\Forms\ConsentComponent; ConsentComponent::make() ->guard($model) ->guard('guard-slug'),
Consent Conditions Page Component
This page will be shown when there are open conditions a user needs to consent.
Slug
The slug can be customized through the config
'page' => [ 'consent_conditions' => [ 'slug' => 'consent-conditions', ], ]
Filament Menu Components
Can be individually enabled/disabled
'page' => [ 'consent_conditions' => [ 'topbar' => true, 'global_search' => false, 'navigation' => false, ], ]
Generate Headings
You can define the heading by adding a closure TermsGuardPlugin::generateConsentConditionsHeadingUsing()
The parameters $livewire, $guard, $user & $panel will be provided;
use Betta\Terms\TermsGuardPlugin; public static function register(Panel $panel): Panel { $panel->plugins([ TermsGuardPlugin::make()->generateConsentConditionsHeadingUsing(fn($livewire, $guard, $user, $panel) => 'Your Heading'), ]); }
Component
The component can be swapped.
'page' => [ 'consent_conditions' => [ 'component' => YourPageComponent::class, ], ]
Commands
Setup Command
Will check if
- the filament plugins are registered to any panel and provide information how to add them
- tables are migrated and will ask to publish&run the migrations
- config is published and ask to publish
- translation is published and ask to publish
php artisan terms:setup
Make Condition Command
Create a condition and attach it to a guard. You will still need to visit the condition management resource. Link will be provided by the command after creation.
php artisan make:terms-condition
Make Guard Command
Create a guard. You will still need to visit the guard management resource. Link will be provided by the command after creation.
php artisan make:terms-guard
Make Terms Model Migration
Events
Terms supplies events if you want to attach further actions after something happened.
Consent Complete
Will dispatch after ConsentConsentConditions is completed
use Betta\Terms\Events\ConsentComplete; public function __construct( User $user, ?string $signedOn = null, ?Guard $guard = null )
Condition Consent
After a condition was accepted.
use Betta\Terms\Events\ConditionConsent; use Betta\Terms\Models\Consent; use Betta\Terms\Models\Condition; public function __construct(Consent $consent) { /** @var User $user */ $user = $consent->user; /** @var Condition $condition */ $condition = $consent->condition; /** @var string $signedOn */ $signedOn = $consent->signed_on; /** @var \Carbon\CarbonInterface $createdAt */ $createdAt = $consent->created_at; }
Successor Activated
When a new condition was activated and the predecessor got obsolete
use Betta\Terms\Events\Condition\SuccessorActivated; use Betta\Terms\Models\Condition; /** @param Condition $condition */ public function __construct($condition) { $predecessor = $condition->predecessor; }
Disabling the guard
If you need to disable the panel guard for some reason or for some user, provide a closure or a just bool to:
use Betta\Terms\TermsManager; use Betta\Terms\Models\Guard; use Filament\Panel; Terms::disableGuard( fn( TermsManager $manager, User $user, Guard $panelGuard, Panel $panel ) : bool => $user->isSuperAdmin(), )
Restricting Access
Terms does not come with permission configuration on purpose. You can enable/disable every Filament Resource/Action through policies as permissions are handled different in every app. Example:
class ConditionPolicy { public function viewAny(User $user): Response | bool { return ! $user->isSuperAdmin(); // will disable the ConditionResource for everyone except "superAdmins" } }
There is one custom Action: Condition "ReplaceAction" which will forward to the model action:
class Condition extends Model { public function replace(): Condition { return Replace::run($this); } } // corresponding policy function class ConditionPolicy { public function replace(User $user, Condition $record): Response | bool { return $user->can('replace'); // e.g. } }
Translations
Localization is available in: [ en, de, es, fr & pt ] at the moment.
Publish the translations using:
php artisan terms:setup
or via the service provider:
php artisan vendor:publish --provider="Betta\Terms\ServiceProvider" --tag=translations
Publish Views
php artisan vendor:publish --provider="Betta\Terms\ServiceProvider" --tag=views
Screenshots
Edit Condition
Consent Conditions Page
Consents Table
Guards Table
Edit Guard
Consent Component Compact Mode
Consent Component Regular Mode
TODO
- Disabling Sources & Components
- Conditions with language / country separation
Credits
License
The MIT License (MIT). Please see License File for more information.







