【发布时间】:2013-07-16 23:15:34
【问题描述】:
我被困在代码中。我设法创建了一个在 db 中添加多个行的表单,但是当我需要使用 product_code 作为 id 时,我不知道如何同时更新它们。
这是表1(产品)结构:
id | product_name | product_code
1 | Name1 | 101
2 | Name2 | 102
3 | Name3 | 103
4 | Name4 | 104
这是表 2 (products_ing) 结构:
id | product_code | ing_name | ing_weight 1 | 101 | INGName1 | 110 2 | 101 | INGName2 | 10 3 | 101 | INGName3 | 54 4 | 101 | INGName4 | 248
这是编辑功能:
public function post_edit($id = null)
{
if(Input::get('submit'))
{
// ID
if($id !== null)
{
$id = trim(filter_var($id, FILTER_SANITIZE_NUMBER_INT));
}
$input = Input::all();
$validation = Validator::make($input);
else
{
foreach ($input as $key => $value)
{
$input[$key] = ($value !== '') ? trim(filter_var($value, FILTER_SANITIZE_STRING)) : null;
}
try
{
DB::table('products')
->whereIn($id)
->update(array(
'product_name' => $items['product_name'],
'product_code' => $items['product_code']
));
}
}
return $this->get_edit($id);
}
有了这个,我只能通过 id 从 products 表中编辑 *product_name* 和 product_code。 但我正在尝试使用相同的 product_code 来更新 db 中的多行,该 product_code 将用作 id。
// 我在 Google 图片 上找到了一张很好的图片,它解释了我在使用 Laravel 时要做的事情:
有解决办法吗?提前谢谢!
【问题讨论】:
标签: php forms sql-update laravel laravel-3