2020-04-29 17:15:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-05-29 23:20:39 +00:00
|
|
|
use App\Application;
|
|
|
|
use App\Http\Requests\VoteRequest;
|
|
|
|
use App\Jobs\ProcessVoteList;
|
|
|
|
use App\Vote;
|
2020-04-29 17:15:54 +00:00
|
|
|
use Illuminate\Http\Request;
|
2020-05-29 23:20:39 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2020-04-29 17:15:54 +00:00
|
|
|
|
|
|
|
class VoteController extends Controller
|
|
|
|
{
|
2020-05-29 23:20:39 +00:00
|
|
|
|
|
|
|
public function vote(VoteRequest $voteRequest, $applicationID)
|
|
|
|
{
|
|
|
|
$application = Application::find($applicationID);
|
|
|
|
|
|
|
|
if (!is_null($application))
|
|
|
|
{
|
|
|
|
$vote = Vote::create([
|
|
|
|
'userID' => Auth::user()->id,
|
|
|
|
'allowedVoteType' => $voteRequest->voteType,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$vote->application()->attach($applicationID);
|
|
|
|
|
|
|
|
Log::info('User ' . Auth::user()->name . ' has voted in applicant ' . $application->user->name . '\'s application', [
|
|
|
|
'voteType' => $voteRequest->voteType
|
|
|
|
]);
|
|
|
|
|
|
|
|
$voteRequest->session()->flash('success', 'Your vote has been registered! You will now be notified about the outcome of this application.');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$voteRequest->session()->flash('error', 'Can\t vote a non existant application!');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cron job will run command that processes votes
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
2020-04-29 17:15:54 +00:00
|
|
|
}
|