mcesar / laravel-survey
此包已被废弃,不再维护。未建议替代包。
Laravel 5.5及更高版本的调查包
1.1.2
2019-06-13 08:43 UTC
Requires
- php: >=7.0
- illuminate/database: ~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0
Requires (Dev)
- phpunit/phpunit: ^5.7|6.2|^7.0
This package is auto-updated.
Last update: 2021-03-14 15:06:33 UTC
README
此包允许您将调查功能添加到Laravel应用程序中
安装后,您可以进行以下操作
// Get all question that a user has Question::answered(false)->get()
安装
Laravel
此包适用于Laravel 5.4或更高版本。如果您使用的是旧版本的Laravel,可以通过composer安装此包
composer require mcesar/laravel-survey
在Laravel 5.5中,服务提供者将自动注册。在框架的旧版本中,只需将服务提供者添加到config/app.php
文件中即可
'providers' => [ // ... MCesar\Survey\SurveyServiceProvider::class, ];
您可以使用以下命令发布迁移
php artisan vendor:publish --provider="MCesar\Survey\SurveyServiceProvider" --tag="migrations"
迁移发布后,您可以通过运行迁移来创建分类、问题和答案表
php artisan migrate
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="MCesar\Survey\SurveyServiceProvider" --tag="config"
发布后,config/survey.php配置文件包含
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 * `MCesar\Survey\Contracts\Category` contract. */ 'category' => MCesar\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 * `MCesar\Survey\Question\Category` contract. */ 'question' => MCesar\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 * `MCesar\Survey\Question\Answer` contract. */ 'answer' => MCesar\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
未测试Lumen支持!
您可以通过Composer安装此包
composer require mcesar/laravel-survey
复制所需的文件
cp vendor/mcesar/laravel-survey/config/permission.php config/survey.php cp vendor/mcesar/laravel-survey/database/migrations/create_survey_tables.php.stub database/migrations/2018_01_01_000000_create_survey_tables.php
现在,运行迁移
php artisan migrate
然后,注册配置和服务提供者
$app->configure('survey'); $app->register(MCesar\Survey\SurveyServiceProvider::class);
使用
此包提供的模型可以像使用任何其他模型一样使用。
扩展
如果您需要扩展现有模型,请注意以下事项
- 您的
Category
模型需要继承MCesar\Survey\Models\Category
模型 - 您的
Question
模型需要继承MCesar\Survey\Models\Question
模型 - 您的
Answer
模型需要继承MCesar\Survey\Models\Answer
模型
如果您需要替换现有模型,请注意以下事项
- 您的
Category
模型需要实现MCesar\Survey\Contracts\Category
契约 - 您的
Question
模型需要实现MCesar\Survey\Contracts\Question
契约 - 您的
Answer
模型需要实现MCesar\Survey\Contracts\Answer
契约
在两种情况下,无论是扩展还是替换,您都需要在配置中指定您的新模型。为此,您必须在发布配置后,在配置文件中更新models.categorie
、models.question
和models.answer
的值,使用此命令
php artisan vendor:publish --provider="MCesar\Survey\SurveyServiceProvider" --tag="config"
测试
composer test
鸣谢
许可协议
麻省理工学院许可证(MIT)。更多信息请参阅许可文件。