public function run() { Eloquent::unguard(); $faker = Faker::create(); foreach (range(1, 5) as $index) { $contactNumber = new ContactNumber(['type' => $faker->numberBetween(1, 3), 'number' => $faker->phoneNumber]); $contactInfo = ContactInfo::create(['address_1' => $faker->streetAddress, 'address_2' => $faker->streetName, 'zip' => $faker->postcode, 'email' => $faker->email]); $contactInfo->contactNumbers()->save($contactNumber); $customer = Customer::create(['name' => $faker->company, 'industry_type' => $faker->numberBetween(1, 3), 'secretary_id' => $faker->numberBetween(5, 7)]); $customer->contactInfo()->save($contactInfo); $representative = CustomerRepresentative::create(['first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'middle_initial' => strtoupper($faker->randomLetter), 'company_position' => 'CEO']); $contactInfo = ContactInfo::create(['email' => $faker->email]); $contactNumber = new ContactNumber(['type' => $faker->numberBetween(1, 3), 'number' => $faker->phoneNumber]); $contactInfo->contactNumbers()->save($contactNumber); $representative->contactInfo()->save($contactInfo); $customer->representatives()->save($representative); } }
public function updateRepresentative($id) { $input = Input::all(); /*echo "<pre>"; print_r($input); die();*/ foreach ($input['array'] as $key => $value) { $record = CustomerRepresentative::find($value['id']); $record->first_name = $value['first_name']; $record->middle_initial = $value['middle_initial']; $record->last_name = $value['last_name']; $record->company_position = $value['company_position']; $record->save(); $email = ContactInfo::find($value['email_id']); $email->email = $value['email']; $email->save(); $number = ContactNumber::find($value['number_id']); $number->number = $value['number']; $number->save(); /*$contact = Contact::find($email->contact_id); $contact->number = $value['new_number']; $contact->save();*/ } return Redirect::back()->with('message', 'Updated representative info')->with('alert-class', 'success'); }