使用L5和我目前的设置来制作博客系统,除了保存博客帖子外,其他一切都已准备就绪。
我有2个按钮。一个创建textarea输入,另一个创建文件上传界面。
从本质上讲,在创建博客文章后,我将得到如下所示的结构:
<form>
<textarea name="text-update">foo</textarea>
<textarea name="text-update">foo</textarea>
<textarea name="text-update">foo</textarea>
<textarea name="text-update">foo</textarea>
<input type="hidden" value="an image url"/>
<input type="hidden" value="an image url"/>
<textarea name="text-update">foo</textarea>
</form>
Run Code Online (Sandbox Code Playgroud)
理想情况下,我希望能够:
public function store()
{
foreach (INPUTS AS INPUT) {
add new row to database with the content and also the type of input.
}
}
Run Code Online (Sandbox Code Playgroud)
这样做的目的是,与其拥有一个博客,不如拥有一个属于博客文章的博客部分。
如果无法做到这一点,那么病态仅需增加输入的名称并弄清楚。
编辑:将元素添加到DOM时,可以使用ID定义数组键以保留数组顺序。
您可以通过[]在名称的末尾添加来使输入成为数组:
<form>
<textarea name="text-update[1]">foo</textarea>
<textarea name="text-update[2]">foo</textarea>
<textarea name="text-update[3]">foo</textarea>
<textarea name="text-update[4]">foo</textarea>
<input type="hidden" name="image[1]" value="an image url"/>
<input type="hidden" name="image[2]" value="an image url"/>
<textarea name="text-update[5]">foo</textarea>
</form>
Run Code Online (Sandbox Code Playgroud)
这会将所有值放入可以迭代的数组中
foreach (Request::get('text-update') as $update) {
//add new row to database with the content and also the type of input.
}
foreach (Request::get('image') as $update) {
//add new row to database with the content and also the type of input.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8880 次 |
| 最近记录: |