/**
  * 
  * @param integer $id
  * @param array $input
  * @param mixed $roles
  * @param mixed $locations
  * @return boolean
  * @throws GeneralException
  */
 public function update($participant, $input, $pcode, $org, $role_id)
 {
     $organization = $this->organization->findOrThrowException($org['org_id']);
     $role = $this->role->findOrThrowException($role_id['role']);
     $area = ['village', 'village_tract', 'township', 'district', 'state', 'country'];
     if (!filter_var($input['email'], FILTER_VALIDATE_EMAIL)) {
         // valid address
         unset($input['email']);
     }
     if (empty($input['nrc_id'])) {
         $input['nrc_id'] = null;
     }
     // get participant
     //$participant = $this->findOrThrowException($id);
     // attach participant to pcode
     if (!empty($pcode['pcode_id'])) {
         $location = PLocation::where('org_id', $org['org_id'])->where('pcode', $pcode['pcode_id'])->first();
         if (!empty($location)) {
             $participant->pcode()->attach($location);
         } else {
             return false;
         }
     }
     // dissociate old organization
     $participant->organization()->dissociate();
     // associate with updated organization
     $participant->organization()->associate($organization);
     // dissociate old role
     $participant->role()->dissociate();
     // associate with updated role
     $participant->role()->associate($role);
     if ($participant->update($input)) {
         return true;
     }
     throw new GeneralException('There was a problem updating this participant. Please try again.');
 }
Esempio n. 2
0
 /**
  * @param $id
  * @return mixed
  */
 public function edit($id)
 {
     $role = $this->roles->findOrThrowException($id, true);
     return view('backend.participant.roles.edit')->withRole($role);
 }