检查Auth用户是否投票,然后对民意调查进行计数?
我遇到了一个阻碍我前进的问题。
到目前为止,我已经尝试获得民意调查的数量:
public function user_dashboard(){
$activepolls = DB::table('larapoll_polls')
->selectRaw('count(*) As total')
->join('larapoll_options', 'larapoll_polls.id', '=', 'larapoll_options.poll_id')
->join('larapoll_votes', 'larapoll_votes.option_id', '=', 'larapoll_options.id')
->where('larapoll_votes.user_id', auth()->user()->id)
->count();
return view('user_dashboard',compact('activepolls'));
}
到目前为止,我认为下面的功能会帮助我,但我不确定。
public function hasVoted($poll_id)
{
$poll = Poll::findOrFail($poll_id);
if ($poll->canGuestVote()) {
$result = DB::table('larapoll_polls')
->selectRaw('count(*) As total')
->join('larapoll_options', 'larapoll_polls.id', '=', 'larapoll_options.poll_id')
->join('larapoll_votes', 'larapoll_votes.option_id', '=', 'larapoll_options.id')
->where('larapoll_votes.user_id', auth()->user()->id)
->where('larapoll_options.poll_id', $poll_id)->count();
return $result !== 0;
}
return $this->options()->where('poll_id', $poll->id)->count() !== 0;
}
简而言之,我在我的网站上制作了一个民意测验箱,我想在该盒子的右角显示民意测验计数。
- 我需要用户未投票的民意调查计数。
- 如果用户对民意调查进行投票,则应从数量上删除。
如果有人能提供帮助,回应将非常感谢..
谢谢。
I encountered an issue that blocks my way forward.
I have tried getting count of polls as of now as shown below:
public function user_dashboard(){
$activepolls = DB::table('larapoll_polls')
->selectRaw('count(*) As total')
->join('larapoll_options', 'larapoll_polls.id', '=', 'larapoll_options.poll_id')
->join('larapoll_votes', 'larapoll_votes.option_id', '=', 'larapoll_options.id')
->where('larapoll_votes.user_id', auth()->user()->id)
->count();
return view('user_dashboard',compact('activepolls'));
}
As of Now I am thinking that this below function would have help me but i am not sure.
public function hasVoted($poll_id)
{
$poll = Poll::findOrFail($poll_id);
if ($poll->canGuestVote()) {
$result = DB::table('larapoll_polls')
->selectRaw('count(*) As total')
->join('larapoll_options', 'larapoll_polls.id', '=', 'larapoll_options.poll_id')
->join('larapoll_votes', 'larapoll_votes.option_id', '=', 'larapoll_options.id')
->where('larapoll_votes.user_id', auth()->user()->id)
->where('larapoll_options.poll_id', $poll_id)->count();
return $result !== 0;
}
return $this->options()->where('poll_id', $poll->id)->count() !== 0;
}
Simply i had made a poll box in my website and i want to show the count of polls in right corner of that box.
- i need the count of poll in which user has not voted.
- if user votes on poll it should remove from count as well.
If anyone can help , the response would much appreciated..
Thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经通过以下代码解决了问题...
在($ unvotedPolls)中,我得到了验证用户未投票的民意调查。
I have Solved The issue by following code...
in ($unvotedpolls) i got the count of polls in which auth user has not voted...