title: Submit data to database using Inertia/React in Laravel
body: <p>I have a form that is supposed to submit order details to the <code>orders</code> table through a custom select element (headlessUI Combobox). The element works fine but I can't seem to pass the data selected to the database, in this case, <code>customer_id</code>.</p>
  <p>Here's the form on the <code>Create.js</code> page:</p>
  <pre class="lang-js prettyprint-override"><code>export default function Create(props) {
  
       const [selected, setSelected] = useState(&quot;&quot;), 
             {customers} = usePage().props
  
       const {post, processing, data, setData} = useForm({
            customer_id: &quot;&quot;,
            
            // other fields here
       })
  
       const customerList = customers.map((customer, index) =&gt; (
           {key: customer.id, name: customer.name}
       ))
  
       const submit = (e) =&gt; {
          e.preventDefault()
          data.customer_id = selected.key
          post(route('resources.orders.store'), data)   
       }
  
       &lt;Form submit={submit}&gt;
           &lt;SelectSearch options={customerList} name={customer_id} value={selected}
                onChange={setSelected} /&gt;
     
           {/* other form elements in here */}
        
           &lt;Button processing={processing} /&gt;
       &lt;/Form&gt;
  
  }
  </code></pre>
  <p>When I <code>console.log(data)</code> I get the selected value in the console: <code>customer_id: 4</code>. When I <code>dd($request-&gt;all())</code> I get the array:</p>
  <pre class="lang-php prettyprint-override"><code>
  ^ array:5 [▼
    &quot;order_date&quot; =&gt; &quot;2022-05-14&quot;
    &quot;customer_id&quot; =&gt; 5
    &quot;service_id&quot; =&gt; &quot;3&quot;
    &quot;quantity&quot; =&gt; &quot;1&quot;
    &quot;discount&quot; =&gt; &quot;0&quot;
  ]
  
  </code></pre>
  <p>But I get the Error <code>SQLSTATE[HY000]: General error: 1364 Field 'customer_id' doesn't have a default value</code> when the data is submitted. The <code>customer_id</code> is a <code>foreignId()</code> field. I can't seem to create the record.</p>