【发布时间】:2015-11-19 15:08:48
【问题描述】:
我有一个关于我想要制作的用户投票系统的问题。
是否可以在用户模型中创建一种角色模型,并且如果用户已投票(这是他们填写的表单),他们将无法查看该页面或无法再次提交表单,因为他们已经投票过一次.
但我不确定这是否可能,你知道是否有办法使这成为可能吗?
更新
用户模型:
protected $table = 'users';
protected $fillable = ['email', 'password', 'voted'];
protected $hidden = ['password', 'remember_token'];
选项模型:
protected $table = 'options';
protected $fillable = ['id, points'];
用户迁移
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('email')->unique();
$table->string('password');
$table->boolean('voted')->default(0);
$table->rememberToken();
$table->timestamps();
});
}
选项迁移
public function up()
{
Schema::create('options', function(Blueprint $table)
{
$table->increments('id');
$table->string('option');
$table->tinyInteger('points');
$table->timestamps();
});
}
也许很高兴知道,在我的 RoundOneController@update 中,我有 2 个 If else 语句。 (如果选择框 1 是数据库中的 id,则更新,否则创建新的。选择框 2 相同) 但是如果有可能在结束后用户表将被更新并且投票列将更改为 1,那么用户将无法再投票。
【问题讨论】: