我在这一行遇到错误$number = "$autonumber[0]/$automonth/$autoyear/proforma";
。这是错误: https: //flareapp.io/share/qm1WG17d 我正在尝试使函数将月份中的形式数量添加到其他数据中。我不知道我做错了什么。有人帮助我吗?
这是具有此功能的控制器,会产生错误:
public function store(Request $request)
{
$autoyear = date('Y');
$automonth = date('m');
$autonumber = DB::table('proforms')
->select(DB::raw('MAX(autonumber) as autonumber'))
->where('automonth', '=', '$automonth')
->where('autoyear', '=', '$autoyear')
->get();
$autonumber[0]++;
$number = "$autonumber[0]/$automonth/$autoyear/proforma";
DB::table('proforms')->insert(
['autonumber' => $number, 'automonth' => $automonth, 'autoyear' => $autoyear]
);
request()->validate([
'user_id' => 'required',
'proformdate' => 'required',
'selldate' => 'required',
'paymentmethod' => 'required',
'paymentdate' => 'required',
'status' => 'nullable',
'city' => 'nullable',
'comments' => 'nullable',
'name' => 'required',
'PKWIU' => 'nullable',
'quantity' => 'required',
'unit' => 'required',
'netunit' => 'required',
'nettotal' => 'required',
'VATrate' => 'required',
'grossunit' => 'required',
'grosstotal' => 'required',
]);
Proform::create($request->all());
return redirect()->route('proforms.index')
->with('success', 'Proform created successfully.');
}
之后 dd($autonumber); 我得到:
Illuminate\Support\Collection {#1328 ▼
#items: array:1 [▼
0 => {#1324 ▼
+"autonumber": null
}
]
}
在 print_r($autonumber); 之后
Illuminate\Support\Collection Object ( [items:protected] => Array ( [0] => stdClass Object ( [autonumber] => ) ) )
杨魅力