2020-04-29 17:15:54 +00:00
|
|
|
<?php
|
|
|
|
|
2020-10-21 00:01:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2020 Miguel Nogueira
|
|
|
|
*
|
|
|
|
* This file is part of Raspberry Staff Manager.
|
|
|
|
*
|
|
|
|
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Raspberry Staff Manager is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-04-29 17:15:54 +00:00
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-05-29 23:20:39 +00:00
|
|
|
use App\Application;
|
|
|
|
use App\Http\Requests\VoteRequest;
|
|
|
|
use App\Vote;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2020-04-29 17:15:54 +00:00
|
|
|
|
|
|
|
class VoteController extends Controller
|
|
|
|
{
|
2020-07-16 20:21:28 +00:00
|
|
|
public function vote(VoteRequest $voteRequest, Application $application)
|
2020-05-29 23:20:39 +00:00
|
|
|
{
|
2020-06-27 18:15:33 +00:00
|
|
|
$this->authorize('create', Vote::class);
|
2020-05-29 23:20:39 +00:00
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
$vote = Vote::create([
|
|
|
|
'userID' => Auth::user()->id,
|
|
|
|
'allowedVoteType' => $voteRequest->voteType,
|
|
|
|
]);
|
2020-09-02 23:11:49 +00:00
|
|
|
$vote->application()->attach($application->id);
|
2020-05-29 23:20:39 +00:00
|
|
|
|
2020-10-21 00:01:41 +00:00
|
|
|
Log::info('User '.Auth::user()->name.' has voted in applicant '.$application->user->name.'\'s application', [
|
|
|
|
'voteType' => $voteRequest->voteType,
|
2020-07-16 20:21:28 +00:00
|
|
|
]);
|
|
|
|
$voteRequest->session()->flash('success', 'Your vote has been registered!');
|
2020-05-29 23:20:39 +00:00
|
|
|
|
|
|
|
// Cron job will run command that processes votes
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
2020-04-29 17:15:54 +00:00
|
|
|
}
|