diff --git a/app/Http/Controllers/PollController.php b/app/Http/Controllers/PollController.php index 018c29902..542647c10 100644 --- a/app/Http/Controllers/PollController.php +++ b/app/Http/Controllers/PollController.php @@ -18,11 +18,13 @@ use App\Http\Requests\VoteOnPoll; use App\Poll; use App\Option; use App\Voter; -use App\Message; use \Toastr; class PollController extends Controller { + /** + * @var ChatRepository + */ private $chat; public function __construct(ChatRepository $chat) @@ -31,22 +33,22 @@ class PollController extends Controller } /** - * Display a listing of the resource. - * + * Show All Polls * + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function index() { $polls = Poll::latest()->paginate(15); - return view('poll.latest', compact('polls')); + return view('poll.latest', ['polls' => $polls]); } /** - * Display the specified resource. - * - * @param int $slug + * Show A Poll * + * @param $slug + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function show($slug) { @@ -55,12 +57,19 @@ class PollController extends Controller $user_has_voted = $poll->voters->where('user_id', $user->id)->isNotEmpty(); if ($user_has_voted) { - return redirect('poll/' . $poll->slug . '/result')->with(Toastr::info('You have already vote on this poll. Here are the results.', 'Hey There!', ['options'])); + return redirect('poll/' . $poll->slug . '/result') + ->with(Toastr::info('You have already vote on this poll. Here are the results.', 'Hey There!', ['options'])); } return view('poll.show', compact('poll')); } + /** + * Vote On A Poll + * + * @param VoteOnPoll $request + * @return Illuminate\Http\RedirectResponse + */ public function vote(VoteOnPoll $request) { $user = auth()->user(); @@ -71,15 +80,16 @@ class PollController extends Controller } if (Voter::where('user_id', $user->id)->where('poll_id', $poll->id)->exists()) { - return redirect('poll/' . $poll->slug . '/result')->with(Toastr::error('Bro have already vote on this poll. Your vote has not been counted.', 'Whoops!', ['options'])); + return redirect('poll/' . $poll->slug . '/result') + ->with(Toastr::error('Bro have already vote on this poll. Your vote has not been counted.', 'Whoops!', ['options'])); } if ($poll->ip_checking == 1) { - $voter = Voter::create([ - 'poll_id' => $poll->id, - 'user_id' => $user->id, - 'ip_address' => $request->ip() - ]); + $vote = new Voter(); + $vote->poll_id = $poll->id; + $vote->user_id = $user->id; + $vote->ip_address =$request->ip(); + $vote->save(); } $poll_url = hrefPoll($poll); @@ -89,9 +99,16 @@ class PollController extends Controller "[url={$profile_url}]{$user->username}[/url] has voted on poll [url={$poll_url}]{$poll->title}[/url]" ); - return redirect('poll/' . $poll->slug . '/result')->with(Toastr::success('Your vote has been counted.', 'Yay!', ['options'])); + return redirect('poll/' . $poll->slug . '/result') + ->with(Toastr::success('Your vote has been counted.', 'Yay!', ['options'])); } + /** + * Show A Polls Results + * + * @param $slug + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ public function result($slug) { $poll = Poll::whereSlug($slug)->firstOrFail(); diff --git a/app/Http/Controllers/Staff/PollController.php b/app/Http/Controllers/Staff/PollController.php index c56c8244d..30ee92a8b 100644 --- a/app/Http/Controllers/Staff/PollController.php +++ b/app/Http/Controllers/Staff/PollController.php @@ -17,7 +17,6 @@ use App\Repositories\ChatRepository; use Illuminate\Http\Request; use App\Poll; use App\Option; -use App\Message; use App\Http\Requests\StorePoll; use Cache; use \Toastr; @@ -34,20 +33,32 @@ class PollController extends Controller $this->chat = $chat; } + /** + * Show All Polls + * + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ public function polls() { $polls = Poll::latest()->paginate(25); - return view('Staff.poll.polls', compact('polls')); - } - public function poll($id) - { - $poll = Poll::where('id', $id)->firstOrFail(); - return view('Staff.poll.poll', compact('poll')); + return view('Staff.poll.polls', ['polls' => $polls]); } /** - * Show the form for creating a new resource. + * Show A Poll + * + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function poll($id) + { + $poll = Poll::where('id', $id)->firstOrFail(); + + return view('Staff.poll.poll', ['poll' => $poll]); + } + + /** + * Poll Add Form * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ @@ -57,10 +68,10 @@ class PollController extends Controller } /** - * Store a newly created resource in storage. + * Add A Poll * * @param StorePoll $request - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Illuminate\Http\RedirectResponse */ public function store(StorePoll $request) { @@ -86,6 +97,7 @@ class PollController extends Controller "A new poll has been created [url={$poll_url}]{$poll->title}[/url] vote on it now! :slight_smile:" ); - return redirect('poll/' . $poll->slug)->with(Toastr::success('Your poll has been created.', 'Yay!', ['options'])); + return redirect('poll/' . $poll->slug) + ->with(Toastr::success('Your poll has been created.', 'Yay!', ['options'])); } } diff --git a/app/Voter.php b/app/Voter.php index f316217f5..ec2702ba9 100644 --- a/app/Voter.php +++ b/app/Voter.php @@ -16,17 +16,6 @@ use Illuminate\Database\Eloquent\Model; class Voter extends Model { - /** - * The Attributes That Are Mass Assignable - * - * @var array - */ - protected $fillable = [ - 'poll_id', - 'user_id', - 'ip_address' - ]; - /** * Belongs To A Poll *