1. Go to this page and download the library: Download multek/laravel-nps library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
multek / laravel-nps example snippets
use Multek\Nps\Traits\HasNpsResponses;
class User extends Authenticatable
{
use HasNpsResponses;
}
$user->dismissNps($survey); // records dismissal with attempt tracking
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}
public function share(Request $request): array
{
return [
...parent::share($request),
'nps' => fn () => \Multek\Nps\Facades\Nps::forUser($request->user()),
];
}
'routes_enabled' => true,
use Multek\Nps\Events\NpsResponseSubmitted;
Event::listen(NpsResponseSubmitted::class, function ($event) {
if ($event->response->is_detractor) {
// Alert customer success team
}
});