>当表单字段固定时,例如
<form name="" action="">
<input type="text" name="username">
<input type="text" name="password">
<input type="email" name="email">
<input type="submit" value="submit">
</form>
然后我们从中
收集数据 $input_data = Input::all();
此代码并插入到数据库中的特定用户名和电子邮件字段中
但
如果形式会像
<form name="" action="">
<input type="text" name="username">
<input type="text" name="password">
<input type="email" name="email">
<input type="email" name="email_1">
<input type="email" name="email_2">
<input type="email" name="email_3">
......
......
......
......
<input type="email" name="email_15">
<input type="submit" value="submit">
</form>
然后在控制器$input_data = Input::all();
中获取 all 值,但我的具体问题是如何分离所有电子邮件和用户名,密码值
我的数据库结构是[ username, password, emails ]
我想将所有电子邮件保存在电子邮件字段中
注意:电子邮件是动态添加的表单 javascript.so 所有时间总电子邮件数量不相同
我不是 100% 确定我理解您在问什么,也不熟悉 Laravel,但是如果您想使用相同类型的多个表单输入让自己更轻松,而不必担心唯一名称,请尝试使用数组字段:
<form name="" action="">
<input type="text" name="username">
<input type="text" name="password">
<input type="email" name="email[]">
<input type="email" name="email[]">
<input type="email" name="email[]">
<input type="email" name="email[]">
<input type="email" name="email[]">
<input type="submit" value="submit">
</form>
它将以单个电子邮件数组的形式出现,您可以使用foreach轻松迭代。如果您尝试将一系列电子邮件保存到一列中,则可以implode()
电子邮件数组(尽管将一堆电子邮件以逗号分隔的字符串存储在一列中可能不是最好的主意)。
无论如何,我不确定这是否有帮助...您可能需要澄清我所说的是否偏离基础。