PHP code example of goldnead / statamic-preference-center

1. Go to this page and download the library: Download goldnead/statamic-preference-center 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/ */

    

goldnead / statamic-preference-center example snippets


use Goldnead\PreferenceCenter\PreferenceCenter;

$url = class_exists(PreferenceCenter::class)
    ? app(PreferenceCenter::class)->urlForToken($subscription->token)
    : null;

$url ??= route('marketing.unsubscribe', $subscription->token);   // the path that always works

use Goldnead\PreferenceCenter\Events\PreferencesChanged;

Event::listen(PreferencesChanged::class, function (PreferencesChanged $event) {
    $event->access;          // Data\Access — identity, brand, proof
    $event->changes;         // list<array{block, target, channel, to}> — only what actually changed
    $event->consentProof();  // 'unsubscribe_token' | 'magic_link' | 'session'
});
bash
php artisan vendor:publish --tag=preference-center-config
php artisan vendor:publish --tag=preference-center-views
php artisan vendor:publish --tag=preference-center-translations