-
📦 Panel Guard
-
📄 Model Guard
-
🔍 Entity discovery (panel & models)
-
🌐 Localized
-
🎨 Intuitive & Responsive UI
composer require e2d2-dev/betta-termsRun the setup command
php artisan terms:setupThis will publish migrations, ask to publish the config file and translations
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;
}Add the ManageTermsPlugin to your panel:
use Betta\Terms\ManageTermsPlugin;
public static function register(Panel $panel): Panel
{
$panel->plugins([
ManageTermsPlugin::make(),
]);
}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(),
]);
}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);
}Conditions can be:
- skippable -> not required
- persistent -> will need consent every time / multiple times
- orderable
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.
- Make sure to add the ManageTermsPlugin to your panel
- Create at least one condition
- Create a guard with the
paneloption - Link them together
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//',
],
],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).
use Betta\Terms\Traits\Model\HasGuardConditions;
use Betta\Terms\Contracts\ModelConditions;
class YourModel implements ModelConditions
{
use HasGuardConditions;
} use Betta\Terms\Filament\Forms\ConsentComponent;
public function form(Schema $schema): Schema
{
return $schema
->components([
ConsentComponent::make()
->compact(),
]);
}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.
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),
]);
}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//',
],
],- 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
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
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.
The slug is autogenerated with timestamp as prefix and with revision suffix.
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.
- Link
- Text
- Markdown
- Iframe
- Simple
- Image
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.
A Condition can only be deleted when they have any consents yet.
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
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.
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(),The component does support further layouts:
use Betta\Terms\Filament\Forms\ConsentComponent;
ConsentComponent::make()
->aside()
->asSection(),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'),This page will be shown when there are open conditions a user needs to consent.
The slug can be customized through the config
'page' => [
'consent_conditions' => [
'slug' => 'consent-conditions',
],
] Can be individually enabled/disabled
'page' => [
'consent_conditions' => [
'topbar' => true,
'global_search' => false,
'navigation' => false,
],
] 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'),
]);
}The component can be swapped.
'page' => [
'consent_conditions' => [
'component' => YourPageComponent::class,
],
] 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:setupCreate 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-conditionCreate 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-guardTerms supplies events if you want to attach further actions after something happened.
Will dispatch after ConsentConsentConditions is completed
use Betta\Terms\Events\ConsentComplete;
public function __construct(
User $user,
?string $signedOn = null,
?Guard $guard = null
)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;
}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;
}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(),
)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.
}
}Localization is available in: [ en, de, es, fr & pt ] at the moment.
Publish the translations using:
php artisan terms:setupor via the service provider:
php artisan vendor:publish --provider="Betta\Terms\ServiceProvider" --tag=translations
php artisan vendor:publish --provider="Betta\Terms\ServiceProvider" --tag=views
- Disabling Sources & Components
- Conditions with language / country separation
The MIT License (MIT). Please see License File for more information.







