You are doing a for loop checking the length of inputCurrName, so it loops through each inputCurrName, which is why you are getting 3 records per FamilyName. In this case, you would only care about 1 record per FamilyName.
There are a few ways you can insert the array of inputCurrName values into 1 record with FamilyName.
You can use serialize() to create a storable representation of a value and unserialize() to decode it when retrieving from the database.
-OR-
You can use implode() to create a comma delimited list when inserting the record. And upon retrieval from the database, use explode() to iterate through each of the comma delimited values.
-OR-
If you prefer json you can do the same with json_encode() and json_decode() the same way as serialize() and unserialize()
+------------+---------------------------------------------------------+
| FamilyName | CurrName |
+------------+---------------------------------------------------------+
| Ali | a:3:{i:0;s:5:"Laura";i:1;s:6:"Peter ";i:2;s:4:"Jack";} |
| Ali | Laura,Peter,Jack |
+------------+---------------------------------------------------------+
Using the following code will give you an example for the table above. curr_name_optional is part of the $user_data array to showcase implode().
<?php
if(isset($_POST) && count($_POST) > 0) {
$inputFamilyName = $_POST['family'];
$inputCurrentName = $_POST['inputCurrName'];
// Your laravel code here..
$user_data = [
'family' => $inputFamilyName,
'curr_name' => serialize($inputCurrentName),
'curr_name_optional' => implode(',', $inputCurrentName),
'curr_name_optional_1' => json_encode($inputCurrentName)
];
echo "<pre>";
print_r($user_data);
echo "</pre>";
}
?>
<form method="post">
Family Name: <input type="text" name="family"/> <br/>
Curr Name: <input type="text" name="inputCurrName[]"/><br/>
Curr Name: <input type="text" name="inputCurrName[]"/><br/>
Curr Name: <input type="text" name="inputCurrName[]"/><br/>
<input type="submit" name="submit" value="submit"/>
</form>
Also, I would make sure to trim and sanitize your form input data before inserting into the database.