data33/laravel-poll 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

data33/laravel-poll

Composer 安装命令:

composer require data33/laravel-poll

包简介

A Laravel 5 package for creating, managing and interacting with polls

README 文档

README

A package for managing polls in Laravel.

Installation

Open your composer.json file and add the following to the require key:

"data33/laravel-poll": "^1.0.1"

After adding the key, run composer update from the command line to install the package

composer update data33/laravel-poll

Configuration

Before you can start using the package we need to set some configurations. To do so you must first publish the config file, you can do this with the following artisan command.

php artisan vendor:publish --provider="Data33\LaravelPoll\PollServiceProvider"

After running the above command, you should see the following changes:

  • A config file should be available at config/polls.php
  • A few new migrations should be placed in your database/migrations folder
  • A few new views should be placed in the folder resources/views/vendor/data33/laravel-poll

If you wish to extend this package, you can specify your own classes to be used as models in the config/polls.php file. Make sure your models extend the existing ones.

Usage

Creating a new poll

You can either create polls manually by using the models directly, or you can use the createPoll helper method.

use Data33\LaravelPoll\Models\Poll;

$title = 'A new poll';
$text = 'A longer text describing the poll';
$type = Poll::TYPE_SINGLE;
// $type = Poll::TYPE_MULTIPLE;
$options = [
    'The first option',
    'The second option',
    'The third option',
];
$endDate = new Carbon\Carbon('2018-12-24 00:00:00');

$poll = Poll::createPoll($title, $text, $type, $options, $endDate);

Adding more options

If you need to add more options to a poll after it has already been created you may use the addOption method.

    $poll->addOption('A fourth option')
        ->addOption('A fifth option');

Voting for an option

Let's assume your App\User model uses the Voter trait.

    auth()->user()
        ->voteFor($poll, $pollOption);

Checking voting status for a voter

    if (auth()->user()->hasVotedInPoll($poll)) {
        echo 'User voted in poll';
    }
    
    if (auth()->user()->hasVotedForOption($poll, $option)) {
        echo 'User voted for specific option';
    }

统计信息

  • 总下载量: 46
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固