如何使用多个输入保存数据

时间:2019-01-19 17:40:58

标签: php laravel laravel-5

  

错误:数组到字符串的转换(SQL:插入到order_productjmlorder_idproduct_id中)的值是(4,23,11),(4, 23,11))

控制器

public function store(Request $request)
{
    $newOrder = new \App\Order;
    $newOrder->name = $request->get('name');
    $newOrder->created_by = \Auth::user()->id;
    $newOrder->save();

    $jml = $request->get('jml');
    $products = $request->get('product');
    $newOrder->products()->attach($products, ['jml'=>$jml]);
    $dt = $newOrder;

    return view('order.details', ['data'=>$dt]);
}

0 个答案:

没有答案