multek/laravel-nps 问题修复 & 功能扩展

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

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

multek/laravel-nps

最新稳定版本:v1.0.0

Composer 安装命令:

composer require multek/laravel-nps

包简介

A simple, focused NPS (Net Promoter Score) package for Laravel applications.

README 文档

README

A simple, focused NPS (Net Promoter Score) package for Laravel applications. Collect user feedback on a 0-10 scale with survey campaigns, cooldown logic, and dismissal tracking.

Installation

composer require multek/laravel-nps

Publish the config and migrations:

php artisan vendor:publish --tag=nps-config
php artisan vendor:publish --tag=nps-migrations
php artisan migrate

Setup

Add the HasNpsResponses trait to your User model:

use Multek\Nps\Traits\HasNpsResponses;

class User extends Authenticatable
{
    use HasNpsResponses;
}

Usage

Creating a Survey

use Multek\Nps\Models\NpsSurvey;

$survey = NpsSurvey::create([
    'name' => 'Q1 2026',
    'description' => 'Quarterly NPS survey',
    'is_active' => true,
]);

Checking Eligibility

$user->canAnswerNps(); // checks cooldown, dismissals, eligibility
$user->canAnswerNps($survey); // for a specific survey

Recording Responses

$response = $user->answerNps($survey, 9, 'Great service!', ['source' => 'web']);

Dismissals

$user->dismissNps($survey); // records dismissal with attempt tracking

Using the Facade

use Multek\Nps\Facades\Nps;

Nps::currentSurvey();           // active survey or null
Nps::forUser($user);            // survey data if eligible, null otherwise
Nps::respond($surveyId, 9);     // record response for auth user
Nps::score($survey);            // NPS score (-100 to 100)
Nps::stats($survey);            // {score, total, promoters, passives, detractors}

Inertia Integration

Share NPS data via your HandleInertiaRequests middleware:

public function share(Request $request): array
{
    return [
        ...parent::share($request),
        'nps' => fn () => \Multek\Nps\Facades\Nps::forUser($request->user()),
    ];
}

In your React component:

const { nps } = usePage().props;
if (nps) {
    // Show NPS modal with nps.survey_id, nps.name, nps.description
}

API Routes

Routes are disabled by default. Enable them in config/nps.php:

'routes_enabled' => true,
Method URI Description
GET /api/nps/current Get active survey for auth user
POST /api/nps/{survey}/respond Submit response
POST /api/nps/{survey}/dismiss Record dismissal

Events

Event When
NpsResponseSubmitted User submits a response
NpsSurveyDismissed User dismisses the NPS prompt
NpsSurveyCompleted Survey reaches end date (dispatch manually)
use Multek\Nps\Events\NpsResponseSubmitted;

Event::listen(NpsResponseSubmitted::class, function ($event) {
    if ($event->response->is_detractor) {
        // Alert customer success team
    }
});

Configuration

See config/nps.php for all options including:

  • cooldown_days — days between surveys (default: 90)
  • max_attempts — max times to show after dismissals (default: 3)
  • attempt_intervals — days between re-shows (default: [3, 7])
  • eligibility_check — custom closure for additional eligibility logic

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固