jeffersongoncalves / laravel-ccpa-opt-out
CCPA/CPRA opt-out ledger for Laravel: Do Not Sell or Share (§1798.120) and Limit the Use of Sensitive Personal Information (§1798.121), Global Privacy Control honored automatically, append-only proof and the 12-month wait before asking to opt back in.
Package info
github.com/jeffersongoncalves/laravel-ccpa-opt-out
pkg:composer/jeffersongoncalves/laravel-ccpa-opt-out
Requires
- php: ^8.2
- illuminate/contracts: ^12.0|^13.0
- illuminate/database: ^12.0|^13.0
- illuminate/http: ^12.0|^13.0
- illuminate/routing: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- illuminate/validation: ^12.0|^13.0
- illuminate/view: ^12.0|^13.0
- jeffersongoncalves/laravel-ccpa: ^1.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- jeffersongoncalves/pest-plugin-database-migrations: ^1.0
- larastan/larastan: ^3.0
- laravel/pint: ^1.24
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-17 16:06:02 UTC
README
Opt-out ledger for the California Consumer Privacy Act, as amended by the CPRA. It is part of the laravel-ccpa suite.
Californians can tell a business not to sell or share their personal information (Cal. Civ. Code §1798.120), and to limit the use of their sensitive personal information (§1798.121). A Global Privacy Control signal sent by the browser counts as an opt-out request (CCPA Regulations §7025). This package:
- records every opt-out and opt-in as a new row, and never updates or deletes a row;
- honors Global Privacy Control with a middleware: a
Sec-GPC: 1request opts the user, or the browser, out of sale and sharing; - works for logged-in consumers and for visitors, who get a random id in an encrypted cookie. A visitor's choices move to the account on login;
- tells you when you may ask again: you must wait 12 months after an opt-out before asking the consumer to opt back in (§1798.135(c)(4));
- offers an endpoint for your "Do Not Sell or Share My Personal Information" and "Limit the Use of My Sensitive Personal Information" links, plus a Blade condition for ad tags.
This package gives you tooling. It does not make you compliant on its own. You still have to stop selling or sharing, and pass the request on to the third parties involved.
Installation
composer require jeffersongoncalves/laravel-ccpa-opt-out php artisan vendor:publish --tag="ccpa-opt-out-migrations" php artisan migrate php artisan vendor:publish --tag="ccpa-opt-out-config" # optional
Usage
use JeffersonGoncalves\CcpaOptOut\Concerns\HasOptOuts; use JeffersonGoncalves\CcpaOptOut\Enums\OptOutRight; class User extends Authenticatable { use HasOptOuts; } $user->optOut(OptOutRight::SaleSharing, 'privacy-page'); $user->hasOptedOut(OptOutRight::SaleSharing); // true $user->optIn(OptOutRight::SaleSharing);
From anywhere, for users or browser ids:
use JeffersonGoncalves\CcpaOptOut\Facades\CcpaOptOut; CcpaOptOut::allowsSaleOrSharing($user); // false after an opt-out of sale/sharing CcpaOptOut::allowsSensitiveUse($user); // false after "limit the use" CcpaOptOut::canAskToOptIn($user, OptOutRight::SaleSharing); // false for 12 months after an opt-out CcpaOptOut::history($user);
Every choice dispatches JeffersonGoncalves\CcpaOptOut\Events\OptOutRecorded. On an opt-out of sale and sharing, use it to tell the third parties you sold or shared the information to (Regulations §7026(f)).
Global Privacy Control
Add the middleware to your web routes:
// bootstrap/app.php ->withMiddleware(function (Middleware $middleware) { $middleware->web(append: ['ccpa.gpc']); })
A request with Sec-GPC: 1 records an opt-out of sale and sharing for the logged-in user, or for the browser's cookie id. It is recorded once. Turn it off with honor_gpc => false.
Links and endpoint
Enable the endpoint with route.enabled => true, then post from your two links:
fetch('/ccpa/opt-out', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': token }, body: JSON.stringify({ right: 'sale_sharing', opted_out: true }), // or 'limit_sensitive' });
When a visitor logs in, the latest choice for each right is copied to the account as a new record, with source claimed. Turn it off with route.claim_on_login => false.
Ad tags
@ccpaSaleAllowed <script src="https://ads.example.com/pixel.js"></script> @endccpaSaleAllowed
The block renders nothing when the user or browser opted out, or when the request carries a GPC signal.
Append-only
Calling update() or delete() on an OptOutRecord throws an exception. The IP address and user agent columns are declared with laravel-ccpa's #[PersonalData], so you can still deidentify them with $record->anonymizePersonalData().
Testing
composer test
Changelog
See CHANGELOG.
License
The MIT License (MIT). See License File.
