Laravel词汇变量错误中的DB事务

时间:2017-09-04 02:26:07

标签: database laravel

我目前正在使用DB-Transaction,它会引发Lexical变量错误 附在这里是我的代码:

 DB::transaction(function ($request) use ($request) {
            $salesman = new Salesman([ 
            'operation_id'      => $request->get('operation_id'),  
            'warehouse_id'      => $request->get('warehouse_id'),
            'salesman_name'     => $request->get('salesman_name'),  
            'address'           => $request->get('address'),  
            'contact_number'    => $request->get('contact_number'),  
            'email_address'     => $request->get('email_address'), 
            'area_id'           => 'pending',     
            ]);
        $salesman->save();
   });
        return view('salesman.index');
 }

1 个答案:

答案 0 :(得分:3)

在我删除函数

中的$ request参数后,它现在正在工作
 DB::transaction(function () use ($request) {
                $salesman = new Salesman([ 
                'operation_id'      => $request->get('operation_id'),  
                'warehouse_id'      => $request->get('warehouse_id'),
                'salesman_name'     => $request->get('salesman_name'),  
                'address'           => $request->get('address'),  
                'contact_number'    => $request->get('contact_number'),  
                'email_address'     => $request->get('email_address'), 
                'area_id'           => 'pending',     
                ]);
            $salesman->save();
       });
            return view('salesman.index');
     }