自定义 laravel 空间 cookie 同意

Customize laravel spatie cookie consent

在我的 laravel 应用程序中,我尝试使用 Spatie cookie consent

实施 cookie 策略通知

在这里,我可以正确地集成通知,但是我想根据我的UI设计更改div内容和样式。

我可以通过更改 git 存储库中提到的供应商文件来进行自定义。

但是由于更改供应商文件不是一个好的做法,我如何自定义我的 cookie 栏及其内容

运行 this 发布观点的命令:

php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-config"

之后你将有 2 个 blade 个文件:

resources/views/vendor/cookieConsent/dialogContents.blade.php resources/views/vendor/cookieConsent/index.blade.php

所以只要你想编辑它们就可以了。

补充:如您所见,blade中可能有这样的东西:

@include('cookieConsent::dialogContents')
  or
@include('cookieConsent::index')

这意味着您的视图文件名为 dialogContents.blade.phpindex.blade.php,应以图形方式定位像这样:

                             packageName::relative.path.with.dots
                 @include('cookieConsent::dialogContents')
"resources/views/vendor" + cookieConsent/ dialogContents .blade.php

                             packageName::relative.path.with.dots
                 @include('cookieConsent::index')
"resources/views/vendor" + cookieConsent/ index .blade.php

您可以编辑它们,或者您可以在 resources/views/... 中的任何地方创建您自己的视图并使用它们,但对于这种情况,您应该将它们包含在默认 laravel 语法(带点)中,如下所示:

@include('folder.subfilder.view')

如果您没有发布您的观点,程序包会自动从 vendor/spatie/laravel-cookie-consent/resources/views/... 默认。

同样,如果需要,您可以自定义翻译,执行 this:

php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-config"

或类似 this 的配置文件:

php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-translations"

重要提示:自定义(视图、翻译、配置等)后,不要忘记刷新缓存

php artisan config:cache
# for Laravel 6 and high:
php artisan optimize