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();
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();
}
}