PHP code example of maize-tech / laravel-nps

1. Go to this page and download the library: Download maize-tech/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/ */

    

maize-tech / laravel-nps example snippets




return [
    /*
    |--------------------------------------------------------------------------
    | Nps model
    |--------------------------------------------------------------------------
    |
    | Here you may specify the fully qualified class name of the nps model class.
    |
    */

    'nps_model' => Maize\Nps\Models\Nps::class,

    /*
    |--------------------------------------------------------------------------
    | Nps answer model
    |--------------------------------------------------------------------------
    |
    | Here you may specify the fully qualified class name of the nps answer
    | model class.
    |
    */

    'nps_answer_model' => Maize\Nps\Models\NpsAnswer::class,

    /*
    |--------------------------------------------------------------------------
    | Nps finder
    |--------------------------------------------------------------------------
    |
    | Here you may specify the fully qualified class name of the nps finder class.
    |
    */

    'nps_finder' => Maize\Nps\DefaultNpsFinder::class,

    /*
    |--------------------------------------------------------------------------
    | Nps visibility
    |--------------------------------------------------------------------------
    |
    | Here you may associate a custom visibility class to a name, which is then
    | used as a reference in the nps model.
    |
    */

    'visibility' => [
        'default' => Maize\Nps\DefaultNpsVisibility::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Nps range
    |--------------------------------------------------------------------------
    |
    | Here you may associate a custom range class to a name, which is then
    | used as a reference in the nps model.
    |
    */

    'range' => [
        'default' => Maize\Nps\DefaultNpsRange::class,
        'minimal' => Maize\Nps\MinimalNpsRange::class,
        'emoji' => Maize\Nps\EmojiNpsRange::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Route configurations
    |--------------------------------------------------------------------------
    |
    | Here you may specify whether routes should be enabled or not.
    | You can also customize the routes prefix and middlewares.
    |
    */

    'routes' => [
        'enabled' => true,
        'prefix' => '',
        'name' => 'nps',
        'middleware' => ['auth:api'],
        'endpoints' => [
            'show' => [
                'middleware' => [],
            ],
            'answer' => [
                'middleware' => [],
            ],
            'delay' => [
                'middleware' => [],
            ],
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Cache
    |--------------------------------------------------------------------------
    |
    | Here you may specify the amount of time, in seconds, where each nps
    | is cached to avoid multiple database queries.
    |
    */

    'cache' => [
        'nps_ttl' => 3600,
        'nps_answer_ttl' => 3600,
    ],
];
bash
php artisan vendor:publish --tag="nps-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="nps-config"
 php
$nps = [
    "id" => 1,
    "question" => "How would you rate our platform?",
    "starts_at" => "2021-01-01",
    "ends_at" => "2021-01-31",
    "range" => "default", // default range is 1-5
    "visibility" => "default", // by default a NPS is always visible
    "updated_at" => "2021-01-01",
    "created_at" => "2021-01-01",
];
 php
class MyCustomNpsRange extends NpsRange
{
    protected static array $values = [2, 4, 6, 8, 10];
}
 php
class EmojiNpsRange extends NpsRange
{
    protected static array $values = [
        '😡' => 1,
        '🙁' => 2,
        '😐' => 3,
        '😉' => 4,
        '😍' => 5,
    ];
}

 php
class MinLoginsVisibility extends NpsVisibility
{
    public function __invoke(Nps $nps): bool
    {
        return auth()->user()->accessLogs()->count() >= 5;
    }
}
 php
'visibility' => [
    'default' => Maize\Nps\DefaultNpsVisibility::class,
    'min_logins' => Path\To\MinLoginsVisibility::class,
]