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
Load the 2 script in the head
  • Loading branch information
Debatty-Tom committed Oct 9, 2025
commit fe7d44c5600bd9ed9323262482eb98fa4ac48ce1
7 changes: 5 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
'prefix' => config('cookieconsent.url.prefix'),
'middleware' => config('cookieconsent.url.middleware')
], function() {
Route::get('script', ScriptController::class)
->name('script');
Route::get('script-cookie', [ScriptController::class, 'getCookieScript'])
->name('script.cookie');

Route::get('script-modal', [ScriptController::class, 'getModalScript'])
->name('script.modal');

Route::post('accept-all', AcceptAllController::class)
->name('accept.all');
Expand Down
20 changes: 7 additions & 13 deletions src/CookiesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,13 @@ protected function getConsentedScripts(bool $withDefault): string
protected function getDefaultScriptTag(): string
{
return '<script '
. 'src="' . route('cookieconsent.script') . '?id='
. md5(\filemtime(LCC_ROOT . '/dist/script.js')) . '" '
. 'src="' . route('cookieconsent.script.cookie') . '?id='
. md5(\filemtime(LCC_ROOT . '/dist/cookies.js')) . '" '
. 'defer'
. '></script>'
. '<script '
. 'src="' . route('cookieconsent.script.modal') . '?id='
. md5(\filemtime(LCC_ROOT . '/dist/modal.js')) . '" '
. 'defer'
. '></script>';
}
Expand All @@ -224,20 +229,9 @@ public function getNoticeMarkup(): string
return view('cookie-consent::cookies', [
'cookies' => $this->registrar,
'policy' => $policy,
'scriptConfig' => $this->generateConfig(),
])->render();
}

protected function generateConfig(): string
{
return json_encode([
'accept.all' => route('cookieconsent.accept.all'),
'accept.essentials' => route('cookieconsent.accept.essentials'),
'accept.configuration' => route('cookieconsent.accept.configuration'),
'reset' => route('cookieconsent.reset'),
]);
}

/**
* Output a single cookie consent action button.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Http/Controllers/ScriptController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@
class ScriptController
{
public function __invoke(Request $request)
{

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since both routes leading to this controller have named methods, the __invoke method can be removed.


public function getCookieScript()
{
$content = str_replace('{config:1}', $this->generateConfig(), file_get_contents(LCC_ROOT . '/dist/cookies.js'));
return response($content)->header('Content-Type', 'application/javascript');
}

public function getModalScript()
{
$content = file_get_contents(LCC_ROOT . '/dist/modal.js');
return response($content)->header('Content-Type', 'application/javascript');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use this opportunity to pass the translation strings to the modal's constructor, like we did for the API routes configuration in getCookiesScript() ?


Expand Down