Hi I have a relatioship between client and phones. Using an array name in the form I managed to save all numbers to a client:
form:
<input type="text" class="form-control phone-number" name="phoneNumbers[work][]" value="">
controller:
$numbers = [];
foreach(Input::get('phoneNumbers') as $phone_type => $array){
foreach($array as $index => $phone_number ){
$phone = new Phone(array(
'name' => $phone_type,
'number' => $phone_number
));
array_push($numbers, $phone);
}
}
$client->phones()->saveMany($numbers);
But now on to updating... Wouldn't it be better to just remove all phones and recreate them with the new ones? As I'm not sure how to write the script to update the phones.
Delete and re-create, easiest way to achieve this (works pretty well, I did it a couple of times for an admin panel).