neo/laravel-early-access 问题修复 & 功能扩展

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

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

neo/laravel-early-access

Composer 安装命令:

composer require neo/laravel-early-access

包简介

Adds an early access page to your Laravel application.

README 文档

README

Laravel Early Access logo

This package makes it easy to add early access mode to your existing application. This is useful for when you want to launch a product and need to gather the email addresses of people who want early access to the application.

Take a look at contributing.md to see a to do list.

⚠️ This version supports Laravel 6 and above. Use version 1.x if you require Laravel 5 support.

Installation

Via Composer

To install via composer, run the following command in the root of your Laravel application:

$ composer require neo/laravel-early-access

Register the middleware Neo\EarlyAccess\Http\Middleware\CheckForEarlyAccessMode at the bottom of your web group middleware in app/Http/Middleware/Kernel.php.

<?php
// [...]

'web' => [
    \App\Http\Middleware\EncryptCookies::class,

    // [...]

    \Neo\EarlyAccess\Http\Middleware\CheckForEarlyAccessMode::class,
],

// [...]

Next, add/update the MAIL_* keys in your .env file. Make sure to include MAIL_FROM_* keys as it is required when sending welcome or goodbye emails to subscribers.

Also, you can optionally add the following environment variables to your .env file:

EARLY_ACCESS_ENABLED=true
EARLY_ACCESS_URL="/early-access"
EARLY_ACCESS_LOGIN_URL="/login"
EARLY_ACCESS_TWITTER_HANDLE=NeoIghodaro
EARLY_ACCESS_VIEW="early-access::index"
EARLY_ACCESS_SERVICE_DRIVER=database
EARLY_ACCESS_SERVICE_DB_TABLE=subscribers

Now migrate the required tables:

$ php artisan migrate

And publish the required assets:

$ php artisan vendor:publish --provider="Neo\EarlyAccess\EarlyAccessServiceProvider"

This will make the config, migrations, views, and assets available inside your applications directory so you can customise them.

TIP: You can append the --tag=assets flag to publish only the asset files which is required. Other available tag values are: config, translations, migrations, views and assets.

To activate early access, you can do either of the following:

  • Run the command $ php artisan early-access --activate
  • Set the EARLY_ACCESS_ENABLED to true in your .env file

TIP: Using the artisan command allows you to add IP addresses that are allowed to bypass the early access screen altogether.

$ php artisan early-access --allow=127.0.0.1 --allow=0.0.0.0

Note that logged in users will also bypass the early access screen.

Configuration

$ php artisan vendor:publish --provider="Neo\EarlyAccess\EarlyAccessServiceProvider" --tag=config

Configuration options

  • enabled - Sets whether the mode is enabled or not. In terms of priority, this is the last thing that is checked to see if the early access screen should be shown. Login status is checked, then artisan command status is checked, then this value is checked. default: false

  • url - The URL the early access screen will be shown at. The client will be redirected to this URL if they do not have access and the mode is enabled. You can set the value to / or any other existing routes. default: /early-access

  • login_url - The URL to your application's login page. This URL will automatically be bypassed even if early access mode is turned on. default: /login

  • twitter_handle - This is used when sending subscription confirmation via email. The user will have the option to tweet with the handle you specify tagged.

  • view - The early access screen view to be loaded. You can publish the views and customise it, or leave the default. default: early-access::index.

  • service - This is the subscription driver. See below for how to create your own driver. default: database.

  • services.database.table_name - The database table name. This is useful is you want to change the name of the database table. You need to do this before you run the migration though. default: subscribers

  • notifications - The default notification classes. You can use your own notification classes if you would like to change how users will be notified when they subscribe or unsubscribe.

Using / or an existing route as the early access URL

To use / or an existing route in your application as the early access URL, you need to do the following:

First, register the service provider manually below the App\Providers\RouteServiceProvider::class in config/app.php.

<?php

return [

    'providers' => [

        // [...]

        App\Providers\RouteServiceProvider::class,
        Neo\EarlyAccess\EarlyAccessServiceProvider::class,

        // [...]

    ],

    // [...]
];

Next, open your composer.json file and add the package in the dont-discover array:

// [...]

"laravel": {
    "dont-discover": [
        "neo/laravel-early-access"
    ]
},

// [...]

Now run composer dump-autoload -o and it should work.

Creating your own subscription service driver

By default, there is a database driver that manages all the users. You can decide to create your own driver though for other services like Mailchimp etc. (If you do, please consider submitting a PR with the driver).

To get started, you need to create a new class that implements the service provider class:

<?php

namespace App\Services\SubscriptionServices;

use Neo\EarlyAccess\Contracts\Subscription\SubscriptionProvider;

class MailchimpService implements SubscriptionProvider
{
    public function add(string $email, string $name = null): bool
    {
        // Implement adding a new subscriber...
    }

    public function remove(string $email): bool
    {
        // Implement removing a subscriber...
    }

    public function verify(string $email): bool
    {
        // Implement verifying a subscriber
    }

    /**
     * @return \Neo\EarlyAccess\Subscriber|false
     */
    public function findByEmail(string $email)
    {
        // Implement returning a subscriber from email
    }
}

Next, register your service in the register method of your app/Providers/AppServiceProvider class:

<?php

// [...]

$this->app->bind('early-access.mailchimp', function () {
    return new \App\Services\SubscriptionServices\MailchimpService;
});

// [...]

NOTE: Leave the early-access. namespace. It is required. Just append the name of your service to the namespace as seen above.

Next, go to your published configuration and change the service driver from database to mailchimp. That's all.

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

Credits

License

Please see the license file for more information.

neo/laravel-early-access 适用场景与选型建议

neo/laravel-early-access 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.13k 次下载、GitHub Stars 达 178, 最近一次更新时间为 2019 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 neo/laravel-early-access 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 178
  • Watchers: 2
  • Forks: 18
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-06