PHPackages                             selli/laravel-gdpr-consent-database - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. selli/laravel-gdpr-consent-database

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

selli/laravel-gdpr-consent-database
===================================

A simple consent database for laravel applications to manage GDPR consents

v1.0.4(11mo ago)181.2k↓100%[2 PRs](https://github.com/Sellinnate/laravel-gdpr-consent-database/pulls)MITPHPPHP ^8.2CI passing

Since Jun 13Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/Sellinnate/laravel-gdpr-consent-database)[ Packagist](https://packagist.org/packages/selli/laravel-gdpr-consent-database)[ Docs](https://github.com/selli/laravel-gdpr-consent-database)[ GitHub Sponsors](https://github.com/selli)[ RSS](/packages/selli-laravel-gdpr-consent-database/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (8)Versions (12)Used By (0)

Laravel GDPR Consent Database
=============================

[](#laravel-gdpr-consent-database)

[![Latest Version on Packagist](https://camo.githubusercontent.com/933a34cbcb78f3632114779a09c208ad28bc5a2e144e90dded13bfc0a45504a6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73656c6c692f6c61726176656c2d676470722d636f6e73656e742d64617461626173652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/selli/laravel-gdpr-consent-database)[![GitHub Tests Action Status](https://camo.githubusercontent.com/b61bf632e7dda5aa1e60ded3698542130d61717d335284d031bcf2654928b0fb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73656c6c696e6e6174652f6c61726176656c2d676470722d636f6e73656e742d64617461626173652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/sellinnate/laravel-gdpr-consent-database/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/187b85bd9f670254b9c2c2d4409742581d095ebf82113b196a576740be8e0e54/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73656c6c696e6e6174652f6c61726176656c2d676470722d636f6e73656e742d64617461626173652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/sellinnate/laravel-gdpr-consent-database/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/358014fd91e39d1bdac3b2e6f841207cbfcf335e7bdc68a6983b31a00c223904/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73656c6c692f6c61726176656c2d676470722d636f6e73656e742d64617461626173652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/selli/laravel-gdpr-consent-database)

A comprehensive Laravel package for managing GDPR consent in your applications. This package provides a complete solution for tracking user consents, managing consent types, and ensuring GDPR compliance.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require selli/laravel-gdpr-consent-database
```

Consent Categories
------------------

[](#consent-categories)

The package supports categorizing consent types to handle different types of consents appropriately:

- `cookie` - For cookie-related consents (technical, profiling, tracking, etc.)
- `other` - For non-cookie consents (marketing, newsletters, etc.)

### Cookie Banner Integration

[](#cookie-banner-integration)

The cookie banner automatically filters and displays only consent types with category `'cookie'`. Other consent types should be managed through your application's registration/preference flows.

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="gdpr-consent-database-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="gdpr-consent-database-config"
```

This is the contents of the published config file:

```
return [
    'text' => [
        'title' => 'Cookie Consent',
        'message' => 'We use cookies to enhance your browsing experience and analyze our traffic. By clicking "Accept All", you consent to our use of cookies.',
        'accept_text' => 'Accept All',
        'reject_text' => 'Reject All',
        'details_text' => 'Cookie Details',
        'back_text' => 'Back',
        'save_text' => 'Save Preferences',
        'icon_text' => 'Cookie Settings',
        'details_header' => 'Cookie Categories',
        'required_text' => '(Required)',
    ],

    'colors' => [
        'banner_background' => '#fff',
        'banner_border' => '#ddd',
        'banner_shadow' => 'rgba(0,0,0,0.1)',
        'text_primary' => '#333',
        'text_secondary' => '#666',
        'button_primary_bg' => '#007cba',
        'button_primary_hover' => '#005a87',
        'button_secondary_bg' => '#f1f1f1',
        'button_secondary_hover' => '#e1e1e1',
        'details_border' => '#eee',
    ],

    'icon' => [
        'position' => 'right',
        'display' => 'icon-with-text',
        'background' => '#007cba',
        'background_hover' => '#005a87',
    ],
];
```

Optionally, you can publish the views using

```
php artisan vendor:publish --tag="laravel-gdpr-consent-database-views"
```

Usage
-----

[](#usage)

### Setup

[](#setup)

After installing the package and running the migrations, you need to add the `HasGdprConsents` trait to your User model or any other model that needs to manage GDPR consents:

```
use Selli\LaravelGdprConsentDatabase\Traits\HasGdprConsents;

class User extends Authenticatable
{
    use HasGdprConsents;

    // ... rest of your model
}
```

### Creating Consent Types

[](#creating-consent-types)

First, you need to create consent types that users can agree to:

```
use Selli\LaravelGdprConsentDatabase\Models\ConsentType;

// Create a required consent type (e.g., Terms and Conditions)
ConsentType::create([
    'name' => 'Terms and Conditions',
    'slug' => 'terms',
    'description' => 'Agreement to the website terms and conditions',
    'required' => true,
    'active' => true,
    'category' => 'other',
]);

// Create cookie-related consent
ConsentType::create([
    'name' => 'Technical Cookies',
    'slug' => 'technical-cookies',
    'description' => 'Essential cookies required for website functionality',
    'required' => true,
    'active' => true,
    'category' => 'cookie',
]);

// Create non-cookie consent
ConsentType::create([
    'name' => 'Marketing Emails',
    'slug' => 'marketing-emails',
    'description' => 'Consent to receive marketing communications',
    'required' => false,
    'active' => true,
    'category' => 'other',
]);
```

### Managing User Consents

[](#managing-user-consents)

Once you have set up consent types, you can manage user consents:

```
// Get the authenticated user
$user = auth()->user();

// Check if the user has given a specific consent
if ($user->hasConsent('marketing-emails')) {
    // User has consented to marketing emails
}

// Give consent (can use slug or consent type ID)
$user->giveConsent('marketing-emails');

// Give consent with additional metadata
$user->giveConsent('marketing-emails', [
    'source' => 'registration_form',
    'version' => '1.0',
]);

// Revoke consent
$user->revokeConsent('marketing-emails');

// Get all active consents for the user
$activeConsents = $user->activeConsents();

// Check if the user has all required consents
if ($user->hasAllRequiredConsents()) {
    // User has all required consents
} else {
    // Get missing required consents
    $missingConsents = $user->getMissingRequiredConsents();
}

### Consent Versioning

#### Overview

The package supports versioning of consent types, which is essential for GDPR compliance when terms or policies change.

#### Usage

```php
// Create a consent type with version
$consentType = ConsentType::create([
    'name' => 'Privacy Policy',
    'slug' => 'privacy-policy',
    'description' => 'Privacy Policy consent',
    'required' => true,
    'active' => true,
    'version' => '1.0',
]);

// Create a new version when terms change
$newVersion = $consentType->createNewVersion([
    'description' => 'Updated Privacy Policy consent',
]);

// Check if a user's consent is for the current version
if ($user->hasConsent('privacy-policy', true)) {
    // User has consented to the current version
} else {
    // User needs to renew consent for the new version
}

// Get all consents that need renewal (expired or outdated version)
$consentsNeedingRenewal = $user->consentsNeedingRenewal();

// Renew a consent with the latest version
$user->renewConsent('privacy-policy');
```

### Consent Expiration

[](#consent-expiration)

#### Overview

[](#overview)

The package also supports consent expiration, allowing you to set validity periods for consents.

#### Usage

[](#usage-1)

```
// Create a consent type with a validity period (in months)
ConsentType::create([
    'name' => 'Marketing Emails',
    'slug' => 'marketing-emails',
    'description' => 'Consent to receive marketing emails',
    'required' => false,
    'active' => true,
    'category' => 'other',
    'version' => '1.0',
    'validity_months' => 12, // Consent valid for 12 months
]);

// Give consent with a custom validity period
$user->giveConsent('marketing-emails', [], 6); // Valid for 6 months

// Check if a consent is expired
$consent = $user->consents()->where('consent_type_id', $consentTypeId)->first();
if ($consent->isExpired()) {
    // Consent is expired
}

// Get all expired consents
$expiredConsents = $user->expiredConsents();

// Get consents that are about to expire within the next 30 days
$soonExpiringConsents = $user->getConsentsExpiringWithinDays(30);
```

### Guest Consent Management

[](#guest-consent-management)

For non-logged-in users, the package provides session-based consent management using technical cookie codes:

```
use Selli\LaravelGdprConsentDatabase\Services\GuestConsentManager;

$guestManager = new GuestConsentManager();

// Give consent for a guest user (uses current session)
$guestManager->giveConsent('marketing-emails', [
    'source' => 'cookie_banner',
]);

// Check if guest has given consent
if ($guestManager->hasConsent('marketing-emails')) {
    // Guest has consented to marketing emails
}

// Get all active consents for guest
$activeConsents = $guestManager->getActiveConsents();

// Check if guest has all required consents
if ($guestManager->hasAllRequiredConsents()) {
    // Guest has all required consents
}

// Work with specific technical cookie code (session ID)
$technicalCookieCode = 'gdpr_abc123_1234567890';
$guestManager->giveConsent('terms', [], null, $technicalCookieCode);

// Revoke guest consent
$guestManager->revokeConsent('marketing-emails', $technicalCookieCode);
```

The guest consent system uses the `guest_consents` table to track session information and links to `user_consents` using the technical cookie code as the session identifier.

### Using the Cookie Consent Seeder

[](#using-the-cookie-consent-seeder)

Run the seeder to populate default cookie consent types:

```
php artisan db:seed --class="Selli\LaravelGdprConsentDatabase\Database\Seeders\CookieConsentSeeder"
```

### Cookie Banner Integration

[](#cookie-banner-integration-1)

The package provides a blade directive for displaying cookie consent banners:

```
{{-- Basic usage --}}
@gdprCookieBanner

{{-- With custom options --}}
@gdprCookieBanner([
    'title' => 'Cookie Preferences',
    'message' => 'We use cookies to improve your experience.',
    'acceptText' => 'Accept All Cookies',
    'rejectText' => 'Reject Optional',
    'consentTypes' => $consentTypes
])
```

#### Publishing Views

[](#publishing-views)

You can publish and customize the cookie banner view:

```
php artisan vendor:publish --tag="laravel-gdpr-consent-database-views"
```

This will publish the view to `resources/views/vendor/gdpr-consent-database/cookie-banner.blade.php`.

#### Customization Options

[](#customization-options)

The cookie banner supports extensive customization through the config file:

- **Text customization**: All button labels, messages, and UI text can be customized
- **Color theming**: Complete color scheme customization including backgrounds, borders, and button colors
- **Icon positioning**: Configure the consent settings icon position (right, left, top, bottom)
- **Icon display**: Choose between icon-only or icon-with-text display modes
- **Responsive design**: Automatic mobile-friendly adaptations

#### JavaScript Integration

[](#javascript-integration)

The cookie banner includes built-in JavaScript for handling user interactions. It automatically:

- Shows the banner for users who haven't given consent
- Handles accept/reject actions via AJAX
- Stores consent state using cookies (`gdpr_consent_given`, `gdpr_session_id`)
- Provides detailed consent management with expandable categories
- Shows a consent settings icon after initial consent is given
- Manages technical cookie codes for session-based guest consent tracking
- Automatically checks consent status on page load and shows appropriate UI

#### Routes

[](#routes)

The package automatically registers these routes for consent management:

- `POST /gdpr/consent/accept-all` - Accept all consent types
- `POST /gdpr/consent/reject-all` - Accept only required consents
- `POST /gdpr/consent/save-preferences` - Save specific consent preferences
- `POST /gdpr/consent/status` - Get current consent status for the session

Make sure to include the CSRF token in your layout:

```

```

Database Structure
------------------

[](#database-structure)

This package creates three main tables:

### consent\_types

[](#consent_types)

Stores the different types of consent that can be requested from users:

- `id`: Primary key
- `name`: Name of the consent type
- `slug`: Unique slug for easy reference
- `description`: Detailed description of what the user is consenting to
- `required`: Boolean indicating if this consent is required
- `active`: Boolean indicating if this consent type is currently active
- `version`: Version string for consent type versioning (default: '1.0')
- `validity_months`: Number of months the consent remains valid (nullable)
- `effective_from`: Timestamp when this version becomes effective (nullable)
- `effective_until`: Timestamp when this version expires (nullable)
- `category`: Category of consent ('cookie' or 'other', default: 'other')
- `metadata`: JSON field for additional data (e.g., legal references)
- `timestamps`: Created and updated timestamps

### user\_consents

[](#user_consents)

Stores the actual user consents:

- `id`: Primary key
- `consentable_id` and `consentable_type`: Polymorphic relationship to the user model
- `consent_type_id`: Foreign key to the consent type
- `consent_version`: Version of the consent type when consent was given (nullable)
- `granted`: Boolean indicating if consent is currently granted
- `granted_at`: Timestamp when consent was granted
- `revoked_at`: Timestamp when consent was revoked (if applicable)
- `expires_at`: Timestamp when consent expires (nullable)
- `ip_address`: IP address from which consent was given
- `user_agent`: User agent from which consent was given
- `metadata`: JSON field for additional data
- `timestamps`: Created and updated timestamps

### guest\_consents

[](#guest_consents)

Stores guest user information for session-based consent tracking:

- `session_id`: Primary key (technical cookie code/session ID)
- `ip_address`: IP address of the guest user
- `user_agent`: User agent of the guest user
- `metadata`: JSON field for additional data
- `timestamps`: Created and updated timestamps

This table works in conjunction with `user_consents` where guest consents are stored using the technical cookie code as the `consentable_id` with `consentable_type` set to the guest consent model.

Extending the Package
---------------------

[](#extending-the-package)

### Custom Consent Types

[](#custom-consent-types)

You can extend the `ConsentType` model to add custom functionality:

```
use Selli\LaravelGdprConsentDatabase\Models\ConsentType;

class MyConsentType extends ConsentType
{
    // Add custom methods or override existing ones

    public function isLegallyRequired()
    {
        return $this->required && isset($this->metadata['legal_basis']);
    }
}
```

### Custom Consent Workflows

[](#custom-consent-workflows)

You can create custom consent workflows by extending the `HasGdprConsents` trait or by creating service classes that use the provided models:

```
use Selli\LaravelGdprConsentDatabase\Models\ConsentType;

class ConsentService
{
    public function processRegistrationConsents(User $user, array $consentData)
    {
        // Process multiple consents at once
        foreach ($consentData as $slug => $isGranted) {
            if ($isGranted) {
                $user->giveConsent($slug, ['source' => 'registration']);
            }
        }

        // Check if all required consents are given
        return $user->hasAllRequiredConsents();
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Filippo Calabrese](https://github.com/filippocalabrese)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance66

Regular maintenance activity

Popularity24

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 61.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

331d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8df9dced104a057028a8e34fb75f3206562b0d0d700fb2dcaea834e490a6cdc8?d=identicon)[sellinnate](/maintainers/sellinnate)

---

Top Contributors

[![FilippoCalabrese](https://avatars.githubusercontent.com/u/15164324?v=4)](https://github.com/FilippoCalabrese "FilippoCalabrese (30 commits)")[![devin-ai-integration[bot]](https://avatars.githubusercontent.com/in/811515?v=4)](https://github.com/devin-ai-integration[bot] "devin-ai-integration[bot] (13 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")

---

Tags

laravelsellilaravel-gdpr-consent-database

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/selli-laravel-gdpr-consent-database/health.svg)

```
[![Health](https://phpackages.com/badges/selli-laravel-gdpr-consent-database/health.svg)](https://phpackages.com/packages/selli-laravel-gdpr-consent-database)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[jeffgreco13/filament-breezy

A custom package for Filament with login flow, profile and teams support.

1.0k1.7M41](/packages/jeffgreco13-filament-breezy)[spatie/laravel-login-link

Quickly login to your local environment

4381.2M1](/packages/spatie-laravel-login-link)[ryangjchandler/laravel-cloudflare-turnstile

A simple package to help integrate Cloudflare Turnstile.

438896.6k2](/packages/ryangjchandler-laravel-cloudflare-turnstile)[spatie/laravel-passkeys

Use passkeys in your Laravel app

444494.4k16](/packages/spatie-laravel-passkeys)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
