承接 sebastiansulinski/laravel-cookies-dialog 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sebastiansulinski/laravel-cookies-dialog

最新稳定版本:v1.1.0

Composer 安装命令:

composer require sebastiansulinski/laravel-cookies-dialog

包简介

Laravel Cookies Dialog

README 文档

README

This package adds simple functionality to manage cookie dialog on your website. It consists of the Controller, which expects request to indicate if third party cookies are being allowed or not and sets the cookie on user's machine accordingly.

You can either use your own front end implementation or use the examples towards the bottom of this page (vuejs/inertiajs/pinia/tailwindcss).

Installation

composer require sebastiansulinski/laravel-cookies-dialog

php artisan vendor:publish --tag=laravel-cookies-dialog

You will now have a config/cookies-dialog.php file available - feel free to update it to your heart's desire.

Pass shared variables to inertia's components

// App\Http\Middleware\HandleInertiaRequests.php

public function __construct(Request $request, private Share $share)
{
    //...
}

public function share(Request $request): array
{
    return array_merge(parent::share($request), $this->share->get());
}

Included ServiceProvider (which is loaded using package discovery) automatically makes all these variables available to all views.

Adding variables to share

You can add more variables to the sharing pot by using Share::set() method from within your AppServiceProvider

// App\Providers\AppServiceProvider

use SSD\CookiesDialog\Utilities\Share;

public function boot(): void
{
    Share::set('googleTagID', config('services.google.tag_id'));
}

Usage

Within view file

@if($thirdPartyCookies)
    // your scripts go here
@endif

Js store

Pinia store with InertiaJs

import { defineStore } from 'pinia';
import { usePage } from '@inertiajs/inertia-vue3';

export const useCookieStore = defineStore('cookies', {
  state: () => ({
    visible: usePage().props.value.showCookiesDialog,
    thirdParty: usePage().props.value.thirdPartyCookies,
  }),
  actions: {
    toggle() {
      this.thirdParty = !this.thirdParty;
    },
    agree() {
      axios.post('/ssd/cookie', { third_party: Number(this.thirdParty) })
        .then(() => window.location.reload())
        .catch(error => console.log(error));
    },
  },
});

Make sure that showCookiesDialog and thirdPartyCookies match your configuration variable names if you've overwritten those.

VueJs Dialog component

<script setup>
import Settings from './Settings.vue';
import { useCookieStore } from '@/stores/cookies';
import { Link } from '@inertiajs/inertia-vue3';
import { ref } from 'vue'

const store = useCookieStore();

const revealed = ref(false);

</script>
<template>
    <div v-if="store.visible" class="w-full fixed inset-x-0 bottom-0 bg-neutral-900 bg-opacity-90 py-8 text-white z-20">
      <div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col lg:flex-row space-y-4 lg:space-y-0">
                <div class="flex-auto">
                    <h2 class="text-2xl font-semibold">Cookies</h2>
                    <p class="text-neutral-300 mt-4">
                        We use cookies to help provide you with the best possible online experience.<br />
                        By using this site, you agree that we may store and access cookies on your device.
                    </p>
                    <p class="text-neutral-300 mt-4">
                        <Link
                            href="/cookies"
                            class="text-yellow-300 hover:text-yellow-400"
                        >
                            Cookie policy</Link>.
                        <span
                            @click.prevent="revealed = !revealed"
                            class="text-yellow-300 hover:text-yellow-400 cursor-pointer"
                        >
                            Cookie settings
                        </span>.
                    </p>
                </div>
                <div>
                    <button
                        v-if="!revealed"
                        @click="store.agree"
                        type="button"
                        class="inline-flex rounded-md border px-4 py-2 text-base font-medium shadow-sm bg-white text-gray-800 border-gray-200 hover:border-gray-400"
                    >I Agree</button>
                </div>
            </div>
            <Settings class="py-8" v-if="revealed" />
        </div>
    </div>
</template>

VueJs Settings component

<script setup>
  import { useCookieStore } from '@/stores/cookies';

  const store = useCookieStore();
</script>
<template>
  <div>
    <div class="grid lg:grid-cols-2 gap-8">
      <div>
        <div class="flex items-center">
          <input
            id="cookies-functional"
            aria-describedby="functional-description"
            name="comments"
            type="checkbox"
            class="h-4 w-4 mr-2 rounded border-neutral-600 border-2 bg-neutral-900 text-primary focus:ring-primary-hover opacity-50"
            checked="checked"
            disabled
          />
          <label for="cookies-functional" class="text-xl text-white">
            Functional cookies
          </label>
        </div>
        <p class="text-neutral-300 mt-6" id="functional-description">
          Functional Cookies are enabled by default at all times so that we can save your preferences for cookie settings and ensure site works and delivers best experience.
        </p>
      </div>
      <div>
        <div class="flex items-center">
          <input
            id="cookies-third-party"
            aria-describedby="third-party-description"
            name="comments"
            type="checkbox"
            class="h-4 w-4 mr-2 rounded border-neutral-600 border-2 bg-neutral-900 text-primary focus:ring-primary-hover"
            @change="store.toggle"
            :checked="store.thirdParty"
          />
          <label for="cookies-third-party" class="text-xl text-white">
            Third party cookies
          </label>
        </div>
        <p class="text-neutral-300 mt-6" id="third-party-description">
          This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.
          Keeping this cookie enabled helps us to improve our website.
        </p>
      </div>
    </div>
    <div class="flex justify-end mt-6">
      <button
        type="button"
        @click="store.agree"
        class="inline-flex rounded-md border px-4 py-2 text-base font-medium shadow-sm bg-white text-gray-800 border-gray-200 hover:border-gray-400"
      >Agree to selected</button>
  </div>
</div>
</template>

Lastly add the component to the footer of your template, and you're done.

sebastiansulinski/laravel-cookies-dialog 适用场景与选型建议

sebastiansulinski/laravel-cookies-dialog 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 163 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 10 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cookies」 「laravel」 「cookies-dialog」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 sebastiansulinski/laravel-cookies-dialog 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sebastiansulinski/laravel-cookies-dialog 我们能提供哪些服务?
定制开发 / 二次开发

基于 sebastiansulinski/laravel-cookies-dialog 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 163
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-25