Registering cookies and choosing categories
mainCookies should be grouped into categories to allow users to grant consent to groups of cookies rather than individual ones. The package provides three base categories:
Cookies::essentials(): Required cookies that cannot be opted-out. Includes:Cookies::essentials()->session(): Registers Laravel's session cookie.Cookies::essentials()->csrf(): Registers Laravel's XSRF-TOKEN cookie.
Cookies::analytics(): For statistics and data collection.Cookies::analytics()->google(string $trackingId, bool $anonymizeIp): Automatically registers Google Analytics cookies and injects the necessary JS scripts into the<head>only when consent is granted.
Cookies::optional(): For utility features. These can be opted-out, so always check for consent before relying on them.
You can also create custom categories using the Cookies::category() method. Custom categories can be accessed via camel-case methods on the facade once defined.
use Whitecube
LaravelCookieConsent
Facades
Cookies;
// Create a custom category
$category = Cookies::category(key: 'my-custom-category');
// Or with a custom class extending Whitecube\LaravelCookieConsent\CookiesCategory
$category = Cookies::category(key: 'my-custom-category', maker: function(string $key) {
return new MyCustomCategory($key);
});
// Access it via camel-case
$category = Cookies::myCustomCategory();