mobihouse/laravel-pennant-cookie 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mobihouse/laravel-pennant-cookie

Composer 安装命令:

composer require mobihouse/laravel-pennant-cookie

包简介

A cookie driver for Laravel Pennant

README 文档

README

Packagist License Packagist Version

Laravel Pennant - Cookie Driver

This package adds the ability to remember feature flags/values from Laravel pennant in a cookie, which allows you to have persisted values for anonymous users.

Important

This driver is most suited for tracking anonymous users, if you want to track actual users it will be more beneficial to use the database driver.

Usage

Install the package using:

composer require mobihouse/laravel-pennant-cookie

And configure it by adding a new store to the config/pennant.php config file:

return [

    'stores' => [
        
        // ...
        'cookie' => [
            'driver' => 'cookie'
        ]

    ]

]

Now that the store is configured set your PENNANT_STORE environment variable to cookie (or set the default key in the pennant config to cookie).

Scope

Laravel Pennant will try to use the auth scope by default and thus look for a current user. Though the driver will work with this it isn't it's intended purpose, so the easiest way to use anonymised scope is setting the default scope to null:

<?php
 
namespace App\Providers;
 
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\ServiceProvider;
use Laravel\Pennant\Feature;
 
class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        Feature::resolveScopeUsing(fn () => null);
 
        // ...
    }
}

Options

By default the cookie that gets set will live for a year, if you want to change the default lifetime you can do the following in the config:

return [

    'stores' => [
        'cookie' => [
            'driver' => 'cookie',
            'lifetime' => 3600, // Live for one hour
        ]
    ]

]

Tests

Running the automated tests can be done by

./vendor/bin/pest

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固