Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix parameters for blade directive
  • Loading branch information
Debatty-Tom committed Nov 14, 2025
commit 0def8727cf54f2c3f47a81c56c4750ae3d447d8d
4 changes: 2 additions & 2 deletions dist/cookies.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/script.js": "/script.js",
"/cookies.js": "/cookies.js",
"/Cookies.js": "/Cookies.js",
"/style.css": "/style.css"
}
2 changes: 1 addition & 1 deletion dist/script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/CookiesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ protected function makeConsentCookie(): CookieComponent
/**
* Output all the scripts for current consent state.
*/
public function renderScripts(bool $withDefault = true, ?string $nonce = null): string
public function renderScripts(string|null $nonce, bool $withDefault = true): string
{
$output = $this->shouldDisplayNotice()
? $this->getNoticeScripts($withDefault, $nonce)
: $this->getConsentedScripts($withDefault, $nonce);
? $this->getNoticeScripts($nonce, $withDefault)
: $this->getConsentedScripts($nonce, $withDefault);

if(strlen($output)) {
$output = '<!-- Cookie Consent -->' . $output;
Expand All @@ -180,23 +180,23 @@ public function renderScripts(bool $withDefault = true, ?string $nonce = null):
return $output;
}

public function getNoticeScripts(bool $withDefault, ?string $nonce = null): string
public function getNoticeScripts(string|null $nonce, bool $withDefault): string
{
return $withDefault ? $this->getDefaultScriptTag($nonce) : '';
}

protected function getConsentedScripts(bool $withDefault, ?string $nonce = null): string
protected function getConsentedScripts(string|null $nonce, bool $withDefault): string
{
$output = $this->getNoticeScripts($withDefault, $nonce);
$output = $this->getNoticeScripts($nonce, $withDefault);

foreach ($this->getConsentResponse()->getResponseScripts() ?? [] as $tag) {
foreach ($this->getConsentResponse($nonce)->getResponseScripts() ?? [] as $tag) {
$output .= $tag;
}

return $output;
}

protected function getDefaultScriptTag(?string $nonce = null): string
protected function getDefaultScriptTag(string|null $nonce): string
{
return '<script '
. 'src="' . route('cookieconsent.script') . '?id='
Expand Down
4 changes: 3 additions & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public function boot()
protected function registerBladeDirectives()
{
Blade::directive('cookieconsentscripts', function (string $expression) {
return '<?php echo ' . Facades\Cookies::class . '::renderScripts(!empty($expression) ? true, ' . $expression . ' : ""); ?>';
$expression = $expression ?: 'null';
return "<?php echo " . Facades\Cookies::class . '::renderScripts('. $expression .', true); ?>';

});
Blade::directive('cookieconsentview', function (string $expression) {
return '<?php echo ' . Facades\Cookies::class . '::renderView(); ?>';
Expand Down
2 changes: 1 addition & 1 deletion webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ let mix = require('laravel-mix');

mix.setPublicPath('dist')
.js('resources/js/script.js', 'dist')
.js('resources/js/cookies.js', 'dist')
.js('resources/js/Cookies.js', 'dist')
.sass('resources/scss/style.scss', 'dist');