Skip to content

Commit ea77af8

Browse files
committed
Pass json routes by a data attribute
1 parent dc3ba8e commit ea77af8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

resources/views/cookies.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969

7070
{{-- STYLES & SCRIPT : feel free to remove them and add your own --}}
7171

72-
<script data-cookie-consent>
72+
<script id="cookies-script" data-cookie-consent data-config="{{ $scriptConfig }}">
7373
{!! file_get_contents(LCC_ROOT . '/dist/script.js') !!}
7474
</script>
7575
<style data-cookie-consent>
7676
{!! file_get_contents(LCC_ROOT . '/dist/style.css') !!}
77-
</style>
77+
</style>

src/CookiesManager.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,20 @@ public function getNoticeMarkup(): string
224224
return view('cookie-consent::cookies', [
225225
'cookies' => $this->registrar,
226226
'policy' => $policy,
227+
'scriptConfig' => $this->generateConfig(),
227228
])->render();
228229
}
229230

231+
protected function generateConfig(): string
232+
{
233+
return json_encode([
234+
'accept.all' => route('cookieconsent.accept.all'),
235+
'accept.essentials' => route('cookieconsent.accept.essentials'),
236+
'accept.configuration' => route('cookieconsent.accept.configuration'),
237+
'reset' => route('cookieconsent.reset'),
238+
]);
239+
}
240+
230241
/**
231242
* Output a single cookie consent action button.
232243
*/

0 commit comments

Comments
 (0)