This plugin provides a comprehensive solution for managing the terms and conditions on your panels.
With this plugin, you can easily create, update, publish, and duplicate terms and conditions, ensuring your users are always up-to-date with the latest policies.
This plugin is also compatible with multi-tenant panels and multi auth guards.
Before use composer
to install this package you need to add this package to your composer.json
file :
{ "repositories": [ { "type": "composer", "url": "https://filament-terms-guard.composer.sh" } ],}
Once the repository has been added to your composer.json
file, you can install this package via composer require
command:
composer require yebor974/filament-terms-guard
You will be prompted to provide your username and password:
Loading composer repositories with package informationAuthentication required (filament-terms-guard.composer.sh):Username: [licensee-email]Password: [license-key]
The username will be your email address and the password will be equal to your license key, followed by a colon (:), followed by the domain you are activating. For example:
Loading composer repositories with package informationAuthentication required (filament-terms-guard.composer.sh):Username: your_email@domain.tldPassword: 8c21df8f-6273-4932-b4ba-8bcc723ef500:domain.tld
You can publish and run the migrations with:
php artisan vendor:publish --tag="filament-terms-guard-migrations"php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="filament-terms-guard-config"
Optionally, you can publish translations files with:
php artisan vendor:publish --tag="filament-terms-guard-translations"
Optionally, you can publish the views using
php artisan vendor:publish --tag="filament-terms-guard-views"
Next, define in your .env
file, which panels need to include user consents with key TERMS_GUARD_PANELS separated by coma:
For panels with id 'admin' and 'customer', you have to declare this line:
TERMS_GUARD_PANELS=admin,customer
If your panel id is not in this config, no consent is asked to users. So, you can disable consent by remove your id panel here.
On panel where you want user consents of new terms and conditions :
use Yebor974\FilamentTermsGuard\TermsGuardPlugin; public function panel(Panel $panel): Panel{ return $panel ->plugins([ TermsGuardPlugin::make() ])}
On panel where you want to manage terms and conditions too :
use Yebor974\FilamentTermsGuard\TermsGuardPlugin; public function panel(Panel $panel): Panel{ return $panel ->plugins([ TermsGuardPlugin::make() ->termsResource() ])}
TermsGuardContract
on your Authentication Model (User by default) and implements methods.use Illuminate\Foundation\Auth\User as Authenticatable;use Yebor974\FilamentTermsGuard\Contracts\TermsGuardContract; class User extends Authenticatable implements TermsGuardContract{ ...}
You can use default HasTermsGuard
trait on your Authentication Model;
use Illuminate\Foundation\Auth\User as Authenticatable;use Yebor974\FilamentTermsGuard\Contracts\TermsGuardContract;use Yebor974\FilamentTermsGuard\Traits\HasTermsGuard; class User extends Authenticatable implements TermsGuardContract{ use HasTermsGuard;}
Or you can define your own criteria for prompting consent form in the needAcceptNewTerms
function:
On this case, you need to implement the terms function too.
use Illuminate\Foundation\Auth\User as Authenticatable;use Yebor974\FilamentTermsGuard\Contracts\TermsGuardContract;use Yebor974\FilamentTermsGuard\Traits\HasTermsGuard; 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); }}
To secure access for your TermResource backend, you can create a policy TermPolicy.php
.
For help, you have a stub file with default policy that can be customized.
Next, it's recommended explicitly register it in AuthServiceProvider.php
file:
use App\Policies\TermPolicy;use Yebor974\FilamentTermsGuard\Models\Term; protected $policies = [ Term::class => TermPolicy::class,];
You can translate you panel id values for select inputs and labels with the translations file of plugin.
After publish translations files, you can define them in panels
array :
'panels' => [ 'admin' => 'Admin Panel', 'super-admin' => 'Super Admin Panel',],
If you dont want group navigation for your TermResource you can put it translation to empty string like this:
'terms' => [ [...] 'navigation' => [ 'group' => '', [...] ]]
You can retrieve the current active terms and conditions for a panel.
use Filament\Facades\Filament;use Yebor974\FilamentTermsGuard\Models\Term; $panel ??= Filament::getCurrentPanel();$currentTerm = Term::getCurrentTerm($panel->getId());
If panel id is not registered on
.env
file, null is return.
Please see CHANGELOG for more information on what has changed recently.
If you discover any security related issues or need support, please email me at contact@julienboyer.re
We offer three types of licenses for our plugin:
For detailed terms and conditions, please see License Options.
User consent view for new terms and conditions:
Form to create new terms and conditions:
Listing of all terms and conditions:
View of a terms and conditions and associated consents: