akaramires / laravel-googleforms by akaramires

Laravel client for Google Forms
54
12
2
Package Data
Maintainer Username: akaramires
Maintainer Contact: e.abdurayimov@gmail.com (Elmar Abdurayimov)
Package Create Date: 2016-05-16
Package Last Update: 2021-01-18
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-19 03:24:58
Package Statistics
Total Downloads: 54
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 12
Total Watchers: 2
Total Forks: 11
Total Open Issues: 2

Laravel 5 Google Forms (using Google Scripts) - Pull requests are welcome!

Installation

Installation using composer:

composer require akaramires/laravel-googleforms

And add the service provider in config/app.php:

Akaramires\GoogleForms\GoogleFormsServiceProvider::class,

Configuration

Laravel

Laravel 5 Google Forms requires configuration.

To get started, first publish the package config file:

php artisan vendor:publish --provider="Akaramires\GoogleForms\GoogleFormsServiceProvider"

You need also get access token

php artisan google-forms:token

Google Scripts

  • Go to https://script.google.com
  • Create new project
  • Create 5 scripts (content of them you can find in vendor/akaramires/laravel-googleforms/scripts directory)
  • Click on Publish->Deploy as API executable
  • Copy API ID and paste into config/googleforms.php

Examples

Simple form

$form = App::make('GoogleForm');

$params = [
    'file_name'                   => sha1(microtime(true)),
    'file_description'            => 'File was created by ' . get_current_user() . ' (' . app()->environment() . ')',
    'title'                       => 'Super title',
    'description'                 => 'Super description',
    'confirmation_message'        => 'Your response has been recorded.',
    'show_progress'               => false,
    'limit_one_response_per_user' => false,
    'shuffle_questions'           => false,
    'show_link_to_respond_again'  => false,
    'publish_and_show'            => false,
    'allow_response_edits'        => false,
    'accepting_responses'         => true,
];

$form->createForm($params);

Form with fields

$fields = [];

$textItem = new TextItem();
// $textItem->setId($field->google_id); # if you have saved field id
$textItem->setTitle('Field title');
$textItem->setHelpText('Field help text');
$textItem->setRequired(true);
$textItem->setIndex(0);

$fields[] = $form->createOrUpdateElement($textItem, true);

$queries = [
    'form'   => $form->createForm($params, true),
    'fields' => $fields,
];

$request = $this->form->batchRequest($queries);;

print_r($request);