I'm trying to get the product Id from the database by using the hidden input but am stuck; I'm getting the error General error: 1366 Incorrect integer value: '[{"id":1}]' for column 'product_id'
. How do I get the product Id from the database?
Blade
<input type="hidden" name="id" value="" />
Controller
Image::create(array_merge($formInput,
[
$id = $request->input('id'),
$product_id = Product::find('id'),
'product_id' => $product_id,
]));
Updated
This is my updated controller.
Image::create(array_merge($formInput,
[
$id = $request->input('id'),
$product = Product::get($id),
'product_id' =>$product->id,
]));
When you use Model::get('column')
style, it returns model object. Not only column value. So you reach column value like this:
Image::create(
array_merge(
$formInput,
[
$id=$request->input('id'),
$product = Product::get($id),
'product_id' => $product->id,
])
);
$id
instead of 'id'
$product
objectid
of the product::find(id)
So in your code, change
$id=$request->input('id'),
$product_id=Product::get('id'),
'product_id' =>$product_id,
to
$id=$request->input('id'),
$product=Product::find($id), /// I assume id is the PK
'product_id' =>$product->id