我正在嘗試使用隱藏輸入從數(shù)據(jù)庫中獲取產(chǎn)品 ID,但卡住了;我收到錯誤General error: 1366 Incorrect integer value: '[{"id":1}]' for column 'product_id'。如何從數(shù)據(jù)庫中獲取產(chǎn)品 ID?刀刃<input type="hidden" name="id" value="" />控制器Image::create(array_merge($formInput, [ $id = $request->input('id'), $product_id = Product::find('id'), 'product_id' => $product_id, ])); 更新這是我更新的控制器。Image::create(array_merge($formInput,[ $id = $request->input('id'), $product = Product::get($id), 'product_id' =>$product->id,]));
2 回答

慕斯709654
TA貢獻1840條經(jīng)驗 獲得超5個贊
當您使用Model::get('column')樣式時,它返回模型對象。不僅是列值。所以你達到這樣的列值:
Image::create(
array_merge(
$formInput,
[
$id=$request->input('id'),
$product = Product::get($id),
'product_id' => $product->id,
])
);

茅侃侃
TA貢獻1842條經(jīng)驗 獲得超22個贊
用戶
$id
而不是'id'
獲取
$product
對象使用
id
該產(chǎn)品的用
::find(id)
所以在你的代碼中,改變
$id=$request->input('id'),
$product_id=Product::get('id'),
'product_id' =>$product_id,
到
$id=$request->input('id'),
$product=Product::find($id), /// I assume id is the PK
'product_id' =>$product->id
- 2 回答
- 0 關注
- 173 瀏覽
添加回答
舉報
0/150
提交
取消