我使用Laravel DB事务来保护我的查询但DB:Transaction
$request->get('remarks')
或参数中的任何内容,这是我的控制器:(我已经仔细检查了我的视图,可能输入的名称是正确的。)
public function store(Request $request)
{
//dd($request->all());
//meat Materials
DB::transaction(function () {
$formula = new Formula([
'project' => 'Project',
'remarks' => $request->get('remarks'),
]);
$current = Carbon::now();
$current = new Carbon();
//$user=auth()->user();
$formula->control_number = '1';
$formula->prepared_by = '1';
$formula->date_prepared = Carbon::now('Asia/Manila');
$formula->time_prepared = Carbon::now('Asia/Manila');
$formula->status = 'pending';
$formula->save();
$meat = new Meat();
$meat->control_number = '1';
$meat->prepared_by = '1';
$meat->save();
});
return view('formula.test');
}
答案 0 :(得分:1)
您需要将变量传递给匿名函数:
DB::transaction(function ($request) use ($request) {
$formula = new Formula([
'project' => 'Project',
'remarks' => $request->get('remarks'),
]);
});