PHP code example of e2d2-dev / betta-terms

1. Go to this page and download the library: Download e2d2-dev/betta-terms library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

e2d2-dev / betta-terms example snippets


   use Betta\Terms\Traits\User\HasConsents;
   use \Betta\Terms\Contracts\CanConsent;
   
   class User extends Authenticatable implements CanConsent
   {
       use HasConsents;
   }
   

   use Betta\Terms\ManageTermsPlugin;
   
   public static function register(Panel $panel): Panel
    {
        $panel->plugins([
            ManageTermsPlugin::make(),
        ]);
   }
   

   use Betta\Terms\TermsGuardPlugin;
   
    public static function register(Panel $panel): Panel
    {
        $panel->plugins([
            TermsGuardPlugin::make(),
        ]);
   }
   

    use Betta\Terms\Filament\Auth\Register;
       
    public static function register(Panel $panel): Panel
    {
        $panel->registration(Register::class);
    }
   

   use Betta\Terms\Terms;
   
    public function boot(): void
    {
        Terms::generatePanelSlugUsing(fn(string $panel) => generate_slug($panel))
    }
   

   'config/betta-terms.php'
   
    'slug' => [
        'panel' => [
            'prefix' => 'panel//',
        ],
    ],
   

   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(),
            ]);
    }
   

   use Betta\Terms\ManageTermsPlugin;
   
   public static function register(Panel $panel): Panel
    {
        $panel->plugins([
            ManageTermsPlugin::make()
                ->registerModel(string $model, ?string $name),
        ]);
   }
   

   use Betta\Terms\Terms;
   
    public function boot(): void
    {
        Terms::generateModelSlugUsing(fn(string $class) => generate_slug($class))
    }
   

   'config/betta-terms.php'
   
    'slug' => [
        'model' => [
            'prefix' => 'model//',
        ],
    ],
   

    use Betta\Terms\Filament\Forms\ConsentComponent;

        ConsentComponent::make()
            ->compact(),
   

    use Betta\Terms\Filament\Forms\ConsentComponent;

        ConsentComponent::make()
            ->aside()
            ->asSection(),
   

    use Betta\Terms\Filament\Forms\ConsentComponent;

        ConsentComponent::make()
            ->guard($model)
            ->guard('guard-slug'),
   

   'page' => [
        'consent_conditions' => [
            'slug' => 'consent-conditions',
        ],
    ]       
   

   'page' => [
        'consent_conditions' => [
            'topbar' => true,
            'global_search' => false,
            'navigation' => false,
         ],
    ]       
   

   use Betta\Terms\TermsGuardPlugin;
   
    public static function register(Panel $panel): Panel
    {
        $panel->plugins([
            TermsGuardPlugin::make()->generateConsentConditionsHeadingUsing(fn($livewire, $guard, $user, $panel) => 'Your Heading'),
        ]);
   }
   

   'page' => [
        'consent_conditions' => [
            'component' => YourPageComponent::class,
         ],
    ]       
   

    use Betta\Terms\Events\ConsentComplete;
   
    public function __construct(
        User $user, 
        ?string $signedOn = null, 
        ?Guard $guard = null
    )

   

    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;
    }


    use Betta\Terms\Events\Condition\SuccessorActivated;
    use Betta\Terms\Models\Condition;
    
    /** @param Condition $condition */
    public function __construct($condition)
    {
        $predecessor = $condition->predecessor;
    }


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(), 
        )
   


class ConditionPolicy
{
    public function viewAny(User $user): Response | bool
    {
        return ! $user->isSuperAdmin(); // will disable the ConditionResource for everyone except "superAdmins"
    }
}

   


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.
    }
}

   
bash
   php artisan terms:setup
   
bash
php artisan terms:setup
bash
php artisan make:terms-condition
bash
php artisan make:terms-guard
bash
php artisan terms:setup
bash
    php artisan vendor:publish --provider="Betta\Terms\ServiceProvider" --tag=translations

bash
    php artisan vendor:publish --provider="Betta\Terms\ServiceProvider" --tag=views