【发布时间】:2021-09-01 21:15:10
【问题描述】:
在我的 laravel 应用程序中,我正在尝试使用 Spatie cookie consent 实现 cookie 策略通知
在这里,我可以正确集成通知,但我想根据我的 UI 设计更改 div 内容和样式。
我可以通过更改 git repo 中提到的供应商文件来进行自定义。
但由于更改供应商文件不是一个好习惯,我如何自定义我的 cookie 栏及其内容
【问题讨论】:
在我的 laravel 应用程序中,我正在尝试使用 Spatie cookie consent 实现 cookie 策略通知
在这里,我可以正确集成通知,但我想根据我的 UI 设计更改 div 内容和样式。
我可以通过更改 git repo 中提到的供应商文件来进行自定义。
但由于更改供应商文件不是一个好习惯,我如何自定义我的 cookie 栏及其内容
【问题讨论】:
运行this命令发布视图:
php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-config"
之后,您将拥有 2 个刀片文件:
resources/views/vendor/cookieConsent/dialogContents.blade.php 资源/视图/供应商/cookieConsent/index.blade.php
所以你可以随意编辑它们。
补充:如您所见,刀片中可能有一些像这样的东西:
@include('cookieConsent::dialogContents')
or
@include('cookieConsent::index')
这意味着您的视图文件名为 dialogContents.blade.php 和 index.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
【讨论】: