Example #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(Motion $motion)
 {
     if (!Auth::user()->can('create-motions')) {
         abort(403, 'You do not have permission to update a motion');
     }
     if (!$motion->user_id != Auth::user()->id && !Auth::user()->can('administrate-motions')) {
         //Is not the user who made it, or the site admin
         abort(401, "This user can not edit motion ({$id})");
     }
     if (!$motion->active && $motion->latestRank) {
         //Motion has closed/expired
         abort(403, 'This motion has expired and can not be edited');
     }
     $motion->secureFill(Request::all());
     if (Request::get('active')) {
         //If you tried to set active, but failed with permissions
         $motion->setActiveAttribute(1);
     }
     if (!$motion->save()) {
         abort(403, $motion->errors);
     }
     return $motion;
 }