PHP code example of brenofortunato / laravel-quiz

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

    

brenofortunato / laravel-quiz example snippets


composer 

php artisan vendor:publish --provider="PandoApps\Quiz\QuizServiceProvider"

php artisan migrate

php artisan db:seed --class=QuestionTypeSeeder

	'models' => [
		'executable'               => App\User::class,      // Model que responderá o questionário
		'executable_column_name'   => 'name',               // Nome da coluna que representa a descrição do model que executa o questionário
		'parent_type'              => App\Holding::class,   // Model que é dono do questionário
		'parent_id'                => 'holding_id',         // Nome da coluna que representa a FK para o model que é dono do questionário
		'parent_url_name'          => 'holdings',           // Nome da tabela do model que é dono do questionário
	]

	/**
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
     **/
    public function executables()
    {
        return $this->morphMany(\PandoApps\Quiz\Models\Executable::class, 'executable');
	}

	/**
	 * @return \Illuminate\Database\Eloquent\Relations\MorphToMany
	 **/
	public function answeredQuestionnaires()
	{
		return $this->morphToMany(\PandoApps\Quiz\Models\Questionnaire::class, 'executable')->withPivot('id', 'score', 'answered')->withTimestamps();
	}

	/**
	* @return \Illuminate\Database\Eloquent\Relations\MorphMany
	**/
	public function questionnaires()
	{
		return $this->morphMany(\PandoApps\Quiz\Models\Questionnaire::class, 'parent');
	}

	Route::group(['prefix' => config('quiz.models.parent_url_name'). '/{' . config('quiz.models.parent_id'). '}'], function () {
		Route::group(['prefix' => 'questionnaires'], function () {
			Route::get('/',                                          ['as'=>'questionnaires.index',   'uses'=>'\PandoApps\Quiz\Controllers\QuestionnaireController@index']);
			Route::get('/create',                                    ['as'=>'questionnaires.create',  'uses'=>'\PandoApps\Quiz\Controllers\QuestionnaireController@create']);
			Route::post('/',                                         ['as'=>'questionnaires.store',   'uses'=>'\PandoApps\Quiz\Controllers\QuestionnaireController@store']);
			Route::get('/{questionnaire_id}',                        ['as'=>'questionnaires.show',    'uses'=>'\PandoApps\Quiz\Controllers\QuestionnaireController@show']);
			Route::match(['put', 'patch'], '/{questionnaire_id}',    ['as'=>'questionnaires.update',  'uses'=>'\PandoApps\Quiz\Controllers\QuestionnaireController@update']);
			Route::delete('/{questionnaire_id}',                     ['as'=>'questionnaires.destroy', 'uses'=>'\PandoApps\Quiz\Controllers\QuestionnaireController@destroy']);
			Route::get('/{questionnaire_id}/edit',                   ['as'=>'questionnaires.edit',    'uses'=>'\PandoApps\Quiz\Controllers\QuestionnaireController@edit']);
		});

		Route::group(['prefix' => 'questions'], function () {
			Route::get('/',                                         ['as'=>'questions.index',   'uses'=>'\PandoApps\Quiz\Controllers\QuestionController@index']);
			Route::get('/{question_id}',                            ['as'=>'questions.show',    'uses'=>'\PandoApps\Quiz\Controllers\QuestionController@show']);
			Route::match(['put', 'patch'], '/{question_id}',        ['as'=>'questions.update',  'uses'=>'\PandoApps\Quiz\Controllers\QuestionController@update']);
			Route::delete('/{question_id}',                         ['as'=>'questions.destroy', 'uses'=>'\PandoApps\Quiz\Controllers\QuestionController@destroy']);
			Route::get('/{question_id}/edit',                       ['as'=>'questions.edit',    'uses'=>'\PandoApps\Quiz\Controllers\QuestionController@edit']);
		});

		Route::group(['prefix' => 'alternatives'], function () {
			Route::get('/',                                        ['as'=>'alternatives.index',   'uses'=>'\PandoApps\Quiz\Controllers\AlternativeController@index']);
			Route::get('/{alternative_id}',                        ['as'=>'alternatives.show',    'uses'=>'\PandoApps\Quiz\Controllers\AlternativeController@show']);
			Route::match(['put', 'patch'], '/{alternative_id}',    ['as'=>'alternatives.update',  'uses'=>'\PandoApps\Quiz\Controllers\AlternativeController@update']);
			Route::delete('/{alternative_id}',                     ['as'=>'alternatives.destroy', 'uses'=>'\PandoApps\Quiz\Controllers\AlternativeController@destroy']);
			Route::get('/{alternative_id}/edit',                   ['as'=>'alternatives.edit',    'uses'=>'\PandoApps\Quiz\Controllers\AlternativeController@edit']);
		});

		Route::group(['prefix' => 'executables'], function () {
			Route::get('/',                                     ['as'=>'executables.index',         'uses'=>'\PandoApps\Quiz\Controllers\ExecutableController@index']);
			Route::get('/{questionnaire_id}/questionnaire',     ['as'=>'executables.statistics',    'uses'=>'\PandoApps\Quiz\Controllers\ExecutableController@statistics']);
			Route::get('{executable_id}/',                      ['as'=>'executables.show',          'uses'=>'\PandoApps\Quiz\Controllers\ExecutableController@show']);
			Route::get('{questionnaire_id}/create/{model_id}',  ['as'=>'executables.create',        'uses'=>'\PandoApps\Quiz\Controllers\ExecutableController@create']);
			Route::post('{questionnaire_id}/store',             ['as'=>'executables.store',         'uses'=>'\PandoApps\Quiz\Controllers\ExecutableController@store']);
			Route::post('start',                                ['as'=>'executables.start',         'uses'=>'\PandoApps\Quiz\Controllers\ExecutableController@start']);
		});

		Route::group(['prefix' => 'answers'], function () {
			Route::get('/',                                     ['as'=>'answers.index',   'uses'=>'\PandoApps\Quiz\Controllers\AnswerController@index']);
			Route::get('/{answer_id}',                          ['as'=>'answers.show',    'uses'=>'\PandoApps\Quiz\Controllers\AnswerController@show']);
		});
	});

	'questionnaires'        => '[s] Questionário         |[p] Questionários',
	'questions'             => '[s] Questão              |[p] Questões',
	'alternatives'          => '[s] Alternativa          |[p] Alternativas',
	'question_types'        => '[s] Tipo da Questão      |[p] Tipo das Questões',
	'answers'               => '[s] Resposta             |[p] Respostas',

	Route::group(['prefix' => 'questionnaires'], function () {
		Route::get('/',                                          ['as'=>'questionnaires.index',   'uses'=>'QuestionnaireController@index']);
		Route::get('/create',                                    ['as'=>'questionnaires.create',  'uses'=>'QuestionnaireController@create']);
		Route::post('/',                                         ['as'=>'questionnaires.store',   'uses'=>'QuestionnaireController@store']);
		Route::get('/{questionnaire_id}',                        ['as'=>'questionnaires.show',    'uses'=>'QuestionnaireController@show']);
		Route::match(['put', 'patch'], '/{questionnaire_id}',    ['as'=>'questionnaires.update',  'uses'=>'QuestionnaireController@update']);
		Route::delete('/{questionnaire_id}',                     ['as'=>'questionnaires.destroy', 'uses'=>'QuestionnaireController@destroy']);
		Route::get('/{questionnaire_id}/edit',                   ['as'=>'questionnaires.edit',    'uses'=>'QuestionnaireController@edit']);
	});