Downloads
Stars
Version
Goes to mceaser/laravel-survey
Just made this package to use in 5.7.* version.
This package allows you to add a survey to your Laravel application
Once installed you can do stuff like this:
// Get all question that a user has
Question::answered(false)->get()
This package can be used in Laravel 5.4 or higher. If you are using an older version of Laravel You can install the package via composer:
composer require jangraviren/laravel-survey
In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just add the service provider in config/app.php
file:
'providers' => [
// ...
JangraViren\Survey\SurveyServiceProvider::class,
];
You can publish the migration with:
php artisan vendor:publish --provider="JangraViren\Survey\SurveyServiceProvider" --tag="migrations"
After the migration has been published you can create the category-, question- and answer-tables by running the migrations:
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --provider="JangraViren\Survey\SurveyServiceProvider" --tag="config"
When published, the config/survey.php
config file contains:
return [
'models' => [
/*
* We need to know which Eloquent model should be used to retrieve your categories.
* Of course, it is often just the "Category" model but you may use whatever you like.
*
* The model you want to use as a Category model needs to implement the
* `JangraViren\Survey\Contracts\Category` contract.
*/
'category' => JangraViren\Survey\Models\Category::class,
/*
* We need to know which Eloquent model should be used to retrieve your questions.
* Of course, it is often just the "Question" model but you may use whatever you like.
*
* The model you want to use as a Question model needs to implement the
* `JangraViren\Survey\Question\Category` contract.
*/
'question' => JangraViren\Survey\Models\Question::class,
/*
* We need to know which Eloquent model should be used to retrieve your answers.
* Of course, it is often just the "Answer" model but you may use whatever you like.
*
* The model you want to use as a Answer model needs to implement the
* `JangraViren\Survey\Question\Answer` contract.
*/
'answer' => JangraViren\Survey\Models\Answer::class,
/*
* We need to know which Eloquent model should be used to assign the answers to.
* Of course, it is often just the "User" model but you may use whatever you like.
*/
'user' => App\User::class,
],
];
Lumen support is not tested!
You can install the package via Composer:
composer require jangraviren/laravel-survey
Copy the required files:
cp vendor/jangraviren/laravel-survey/config/permission.php config/survey.php
cp vendor/jangraviren/laravel-survey/database/migrations/create_survey_tables.php.stub database/migrations/2018_01_01_000000_create_survey_tables.php
Now, run your migrations:
php artisan migrate
Then, register the configuration and the service provider:
$app->configure('survey');
$app->register(JangraViren\Survey\SurveyServiceProvider::class);
The models supplied by this package can be used the same as any other model you make.
If you need to EXTEND the existing models note that:
Category
model needs to extend the JangraViren\Survey\Models\Category
modelQuestion
model needs to extend the JangraViren\Survey\Models\Question
modelAnswer
model needs to extend the JangraViren\Survey\Models\Answer
modelIf you need to REPLACE the existing models you need to keep the following things in mind:
Category
model needs to implement the JangraViren\Survey\Contracts\Category
contractQuestion
model needs to implement the JangraViren\Survey\Contracts\Question
contractAnswer
model needs to implement the JangraViren\Survey\Contracts\Answer
contractIn BOTH cases, whether extending or replacing, you will need to specify your new models in the configuration. To do this you must update the models.categorie
, models.question
and models.answer
values in the configuration file after publishing the configuration with this command:
php artisan vendor:publish --provider="JangraViren\Survey\SurveyServiceProvider" --tag="config"
composer test
The MIT License (MIT). Please see License File for more information.