PHP code example of matt-daneshvar / laravel-survey

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

    

matt-daneshvar / laravel-survey example snippets


$survey = Survey::create(['name' => 'Cat Population Survey']);

$survey->questions()->create([
     'content' => 'How many cats do you have?',
     'type' => 'number',
     'rules' => ['numeric', 'min:0']
 ]);

$survey->questions()->create([
    'content' => 'What\'s the name of your first cat',
]);

$survey->questions()->create([
    'content' => 'Would you want a new cat?',
    'type' => 'radio',
    'options' => ['Yes', 'Oui']
]);

$survey = Survey::create(['name' => 'Cat Population Survey']);

$one = $survey->sections()->create(['name' => 'Part One']);

$one->questions()->create([
    'content' => 'How many cats do you have?',
    'type' => 'number',
    'rules' => ['numeric', 'min:0']
]);

$two = $survey->sections()->create(['name' => 'Part Two']);

$two->questions()->create([
    'content' => 'What\'s the name of your first cat?',
]);

$two->questions()->create([
    'content' => 'Would you want a new cat?',
    'type' => 'radio',
    'options' => ['Yes', 'Oui']
]);

(new Entry)->for($survey)->fromArray([
    'q1' => 'Yes',
    'q2' => 5
])->push();

(new Entry)->for($survey)->by($user)->fromArray($answers)->push();

Survey::create(['settings' => ['accept-guest-entries' => true]]);

Survey::create(['settings' => ['limit-per-participant' => 1]]);

Question::create([
    'content' => 'How many cats do you have?', 
    'rules' => ['numeric', 'min:0']
]);

class SurveyEntriesController extends Controller
{
    public function store(Survey $survey, Request $request)
    {
        $answers = $request->validate($request, $survey->rules);
        
        (new Entry)->for($survey)->fromArray($answers)->push();
    }
}
bash
php artisan vendor:publish --provider="MattDaneshvar\Survey\SurveyServiceProvider" --tag="migrations" 
bash
php artisan migrate 
bash
php artisan vendor:publish --provider="MattDaneshvar\Survey\SurveyServiceProvider" --tag="views"

<your-views-director>/vendor/survey/questions/types/custom-select.blade.php