/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 5) as $index) {
         Counselor::create(['identifier' => $faker->regexify('[0-9]{10}'), 'first_name' => $faker->firstName(), 'last_name' => $faker->lastName(), 'hire_date' => $faker->dateTimeBetween($startDate = '-3 years')]);
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     $attendeeIds = Attendee::lists('id')->all();
     $counselorIds = Counselor::lists('id')->all();
     foreach ($attendeeIds as $attendeeId) {
         DB::table('attendee_counselor')->insert(['attendee_id' => $attendeeId, 'counselor_id' => $faker->randomElement($counselorIds), 'created_at' => Carbon::now()]);
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $counselor = Counselor::find($id);
     if (!$counselor) {
         return $this->respondNotFound('Counselor does not exist.');
     }
     if ($counselor->delete()) {
         return $this->respond(['message' => 'The counselor has been deleted.']);
     } else {
         return $this->respondUnprocessableEntity('There was a problem deleting the counselor.');
     }
 }
 /**
  * Update the counselor associated with the attendee.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function updateCounselor($id)
 {
     $attendee = Attendee::find($id);
     if (!$attendee) {
         return $this->respondNotFound('Attendee does not exist.');
     }
     $counselorId = Input::get('counselor_id');
     if (!$counselorId) {
         return $this->respondUnprocessableEntity('Parameters failed validation for an attendee.');
     }
     try {
         $newCounselor = Counselor::findOrFail($counselorId);
     } catch (ModelNotFoundException $e) {
         return $this->respondUnprocessableEntity('Counselor provided does not exist');
     }
     //We pass validation. Now softDelete the existing counselor and replace it.
     $currentCounselor = $attendee->counselor;
     if ($currentCounselor->id != $newCounselor->id) {
         $attendee->reassignCounselor($newCounselor->id);
         return $this->respond(['message' => "The attendee/counselor assignment has been updated."]);
     }
     return $this->respond(['message' => "The attendee/counselor assignment remains unchanged."]);
 }