PHP code example of statikbe / laravel-surveyhero

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

    

statikbe / laravel-surveyhero example snippets


'question_mapping' => [
    [
        'survey_id' => 1234567,
    ],
    [
        'survey_id' => 4897492,
    ],
    ...
];

'question_mapping' => [
    [
        'survey_id' => 1234567,
        'collectors' => [986362,524948],
    ],
    [
        'survey_id' => 4897492,
        'collectors' => env('COLLECTOR_IDS'),
    ],
    ...
];

'question_mapping' => [
    [
        'survey_id' => 1234567,
        'collectors' => [986362,524948],
        'use_resume_link' => true,
        'questions' => [
            #example numeric input
            1000005 => [
                'question_id' => 1000005,
                'type' => 'text',
                'field' => 'custom_question_field_name',
            ],
            #example choice list
            1000002 => [
                'question_id' => 1000002,
                'type' => 'choices',
                'field' => 'another_custom_question_field_name',
                'answer_mapping' => [
                    13509166 => 10,
                    13509167 => 1000,
                    13509168 => 1337,
                ],
                'mapped_data_type' => 'int',
            ],
        ]
    ],
    ...
];

1000005 => [
    'question_id' => 1000005,
    'type' => 'text',
    'field' => 'question_5',
],

1000006 => [
    'question_id' => 1000006,
    'type' => 'number',
    'field' => 'age',
    'mapped_data_type' => 'int',
],

1000002 => [
    'question_id' => 1000002,
    'type' => 'choices',
    'field' => 'question_4',
    'answer_mapping' => [
        13509166 => 1,
        13509167 => 2,
        13509168 => 3,
    ],
    'mapped_data_type' => 'int',
],

1000001 => [
    'question_id' => 1000001,
    'type' => 'choice_table',
    'subquestion_mapping' => [
        13509163 => [
            'question_id' => 13509163,
            'field' => 'question_1',
        ],
        13509164 => [
            'question_id' => 13509164,
            'field' => 'question_2',
        ],
        13509165 => [
            'question_id' => 13509165,
            'field' => 'question_3',
            'answer_mapping' => [
                13509163 => 3,
                13509164 => 2,
                13509165 => 1,
            ],
        ],
    ],
    'answer_mapping' => [
        13509163 => 1,
        13509164 => 2,
        13509165 => 3,
    ],
    'mapped_data_type' => 'int', //can also be string if the values are strings in answer_mapping
]
 
'surveyhero_link_parameters_mapping' => [
     'username' => [
         'name' => 'user_name'                        (the target column name on the survey_response table)
     ],
     'user_uuid' => [
         'name' => 'user_id',                         (the target column name on the survey_response table)
         'entity' => \App\Models\User::class,         (the model to query)
         'value' => 'uuid',                           (the column on the entity to query)
         'field' => 'id',                             (the column on the entity to select)
     ],
],
 
'models' => [
    'survey' => Statikbe\Surveyhero\Models\Survey::class,
    'survey_question' => Statikbe\Surveyhero\Models\SurveyQuestion::class,
    'survey_answer' => Statikbe\Surveyhero\Models\SurveyAnswer::class,
    'survey_response' => Statikbe\Surveyhero\Models\SurveyResponse::class,
    'survey_question_response' => Statikbe\Surveyhero\Models\SurveyQuestionResponse::class,
],
 
'table_names' => [
    'surveys' => [
        'name' => 'surveys',
        'foreign_key' => 'survey_id',
    ],
    'survey_questions' => [
        'name' => 'survey_questions',
        'foreign_key' => 'survey_question_id',
    ],
    'survey_answers' => [
        'name' => 'survey_answers',
        'foreign_key' => 'survey_answer_id',
    ],
    'survey_responses' => [
        'name' => 'survey_responses',
        'foreign_key' => 'survey_response_id',
    ],
    'survey_question_responses' => [
        'name' => 'survey_question_responses',
        'foreign_key' => 'survey_question_response_id',
    ],
],
 
use Statikbe\Surveyhero\Http\Controllers\Api\SurveyheroWebhookController;

Route::post('/process-surveyhero-response-completed', [SurveyheroWebhookController::class, 'handleResponseCompletedWebhook'])
    ->name('surveyhero_response_webhook');
 
use Statikbe\Surveyhero\Facades\Surveyhero;

Surveyhero::webhookRoutes();
bash
php artisan vendor:publish --tag="surveyhero-config"
bash
php artisan vendor:publish --tag="surveyhero-migrations"
php artisan migrate
shell 
php artisan surveyhero:add-webhooks --eventType=response.completed --url=https://webhook.site/complete-response
shell 
php artisan surveyhero:list-webhooks --survey=12345
shell 
php artisan surveyhero:delete-webhook --survey=12345 --webhook=2553
shell
 php artisan surveyhero:responses-export --survey=1451654 --linkParameter=organisation --extraResponseCol=survey_completed --extraResponseCol=survey_start_date