示例#1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(Vote $vote)
 {
     //Check if the user has permission to cast votes
     if (!Auth::user()->can('create-votes')) {
         abort(401, 'You do not have permission to update a vote');
     }
     if ($vote->user_id != Auth::user()->id) {
         abort(401, "This user does not have permission to edit this vote");
     }
     //Validate the input
     $vote->secureFill(Request::all());
     if (!$vote->save()) {
         abort(403, $vote->errors);
     }
     //event(new UserChangedVote($vote));
     return $vote;
 }