如何从Laravel中的数据库获取产品ID

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,
       ])
); 
  1. User $id instead of 'id'
  2. get $product object
  3. Use the id of the product
  4. Use ::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