PHP code example of yo1l / laravel-typeform
1. Go to this page and download the library: Download yo1l/laravel-typeform 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' );
yo1l / laravel-typeform example snippets
php artisan vendor:publish --provider="Yo1L\LaravelTypeForm\TypeFormServiceProvider"
return [
'debug' => false ,
'token' => env('TYPEFORM_TOKEN' ),
'headers' => [],
'base_uri' => 'https://api.typeform.com/' ,
'webhook' => [
'base_uri' => env('TYPEFORM_WEBHOOK_BASE_URI' , null ),
'uri' => env('TYPEFORM_WEBHOOK_URI' , '/api/webhook/typeform' ),
'tag' => env('TYPEFORM_WEBHOOK_TAG' , null ),
'secret' => env('TYPEFORM_WEBHOOK_SECRET' , null ),
'verify_ssl' => env('TYPEFORM_WEBHOOK_VERIFY_SSL' , true ),
],
];
$formChunks = TypeForm::getFormsByChunk();
foreach ($formChunks as $forms) {
foreach ($forms['items' ] as $form) {
Log::info($form['id' ]);
}
}
$jsonForm = TypeForm::getForm($this ->formSlug);
foreach ($jsonForm['fields' ] as $item) {
Log::debug($item)
if ($item['type' ] == 'group' ) {
foreach ($item['properties' ]['fields' ] as $subItem) {
Log::debug($subItem);
}
}
}
$params = ['completed' => true ];
foreach (TypeForm::getResponsesByChunk("MyFormId" , $params) as $responses) {
foreach ($responses['items' ] as $jsonResponse) {
$submitted_at = Carbon::parse($jsonResponse['submitted_at' ]);
$id = $jsonResponse['token' ];
foreach ($jsonResponse['answers' ] as $jsonAnswer) {
}
}
}
namespace App \Http \Controllers \API ;
use Illuminate \Http \Request ;
use App \Http \Controllers \Controller ;
use TypeForm ;
class TypeFormController extends Controller
{
public function __invoke (Request $request)
{
TypeForm::validatePayload($request);
$formId = $request->form_response['form_id' ] ?? null ;
abort_if($formId == null , 403 );
return ['ok' ];
}
}