/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     \App::setLocale(Auth::user()->language());
     $user = Auth::user();
     $validator = Validator::make($request->all(), ['proposition' => 'required|max:140', 'proposition_description' => 'min:10', 'deadline' => 'required|between:1,3']);
     if ($validator->fails()) {
         return redirect()->back()->withInput($request->all())->withErrors($validator->errors());
     } else {
         if ($user->belongsToSchool() == true) {
             $deadlineId = $request->input('deadline');
             // Deadlines: 1=2weeks, 2=1month, 3=2months
             switch ($deadlineId) {
                 case 1:
                     $deadline = Carbon::now()->addWeeks(2)->toDateTimeString();
                     break;
                 case 2:
                     $deadline = Carbon::now()->addMonth()->toDateTimeString();
                     break;
                 case 3:
                     $deadline = Carbon::now()->addMonths(2)->toDateTimeString();
                     break;
             }
             $proposition = Proposition::create(["proposer_id" => $user->userId(), "propositionSort" => $request->input('proposition'), "propositionLong" => $request->input('proposition_description'), "deadline" => $deadline]);
             // Register new tags
             preg_match_all("/#([a-zA-Z0-9_]+)/", $request->input('proposition') . " " . $request->input('proposition_description'), $matches);
             foreach (array_unique($matches[1]) as $tagString) {
                 $tag = with(new TagsFactory())->findOrCreate($tagString);
                 $proposition->addTag($tag);
             }
             return redirect()->route('profile.propositions')->with('status', trans('messages.profile.create_proposition.success'));
         } else {
             abort(403, trans('messages.unauthorized'));
         }
     }
 }
 public function getDownvotes($id)
 {
     $proposition = Proposition::find($id);
     $downvotes = 0;
     $downvotes = Votes::wherePropositionIdAndVoteValue($proposition->propositionId(), 0)->get();
     $downvotesSum = 0;
     foreach ($downvotes as $downvote) {
         $downvotesSum++;
     }
     return $downvotesSum;
 }