我在這一行遇到錯(cuò)誤$number = "$autonumber[0]/$automonth/$autoyear/proforma";。這是錯(cuò)誤: https: //flareapp.io/share/qm1WG17d 我正在嘗試使函數(shù)將月份中的形式數(shù)量添加到其他數(shù)據(jù)中。我不知道我做錯(cuò)了什么。有人幫助我嗎?這是具有此功能的控制器,會(huì)產(chǎn)生錯(cuò)誤: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] => ) ) )
1 回答

楊魅力
TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊
有一個(gè)誤解,下面的代碼不會(huì)返回一個(gè)整數(shù),而是一個(gè)具有以下結(jié)構(gòu)的對(duì)象:{"autonumber": 42}。
$autonumber = DB::table('proforms')
->select(DB::raw('MAX(autonumber) as autonumber'))
->where('automonth', '=', '$automonth')
->where('autoyear', '=', '$autoyear')
->get();
更改代碼以使用該結(jié)構(gòu)。
$autonumber[0]->autonumber++;
$number = $autonumber[0]->autonumber;
$number = "$number/$automonth/$autoyear/proforma";
- 1 回答
- 0 關(guān)注
- 117 瀏覽
添加回答
舉報(bào)
0/150
提交
取消