Skip to content

Commit 2a1ac48

Browse files
committed
Added CookiesServiceProvider with stub
1 parent 784a4d8 commit 2a1ac48

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/CookiesServiceProvider.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Whitecube\LaravelCookieConsent;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
abstract class CookiesServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* Register any application services.
11+
*/
12+
public function register()
13+
{
14+
$this->booted(function () {
15+
$this->registerCookies();
16+
});
17+
}
18+
19+
/**
20+
* Define the cookies users should be aware of.
21+
*/
22+
abstract protected function registerCookies(): void;
23+
24+
/**
25+
* Bootstrap any application services.
26+
*/
27+
public function boot()
28+
{
29+
//
30+
}
31+
}

stubs/CookiesServiceProvider.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use Whitecube\LaravelCookieConsent\Consent;
6+
use Whitecube\LaravelCookieConsent\Facades\Cookies;
7+
use Whitecube\LaravelCookieConsent\CookiesServiceProvider as ServiceProvider;
8+
9+
class CookiesServiceProvider extends ServiceProvider
10+
{
11+
/**
12+
* Define the cookies users should be aware of.
13+
*/
14+
protected function registerCookies(): void
15+
{
16+
// Register Laravel's base cookies under the "required" cookies section:
17+
Cookies::essentials()
18+
->session()
19+
->csrf();
20+
21+
// Register all Analytics cookies at once using one single shorthand method:
22+
// Cookies::analytics()
23+
// ->google(env('GOOGLE_ANALYTICS_ID'));
24+
25+
// Register custom cookies under the pre-existing "optional" category:
26+
// Cookies::optional()
27+
// ->name('darkmode_enabled')
28+
// ->description('This cookie helps us remember your preferences regarding the interface\'s brightness.')
29+
// ->duration(120);
30+
// ->accepted(fn(Consent $consent, MyDarkmode $darkmode) => $consent->cookie(value: $darkmode->getDefaultValue()));
31+
}
32+
}

0 commit comments

Comments
 (0)