'Add row and write ticketId automatically in Laravel 8

I want to insert the ticketId to insert the data in the table that I created with add row. Now I can get the user_id to be written, but I have not yet written ticketId. The table is the same, and I have the ticketId field. How can I recall the ticketId?. I also need to write the ticketId. How can I add it?

Controller

public function addMorePost(Request $request, $ticketId)
{
    $request->validate([
        'addmore.*.desc_art' => 'required',
        'addmore.*.marca' => 'required',
        'addmore.*.modello' => 'required',
        'addmore.*.unita' => 'required',
        'addmore.*.quantita' => 'required',
    ]);

    foreach ($request->addmore as $key => $value) {
        TicketReply::create(array_merge($value, 
            ['user_id' => Auth::user()->id]));
    }

    return back()->with('eseguito', 'Materiale Caricato.');
}

        <script type="text/javascript">

            var i = 0;

            $("#add").click(function(){

                ++i;

                $("#dynamicTable").append('<tr><td><input type="text" name="addmore['+i+'][desc_art]" class="form-control" /></td><td><input type="text" name="addmore['+i+'][marca]" class="form-control" /></td><td><input type="text" name="addmore['+i+'][modello]" class="form-control" /></td><td><input type="text" name="addmore['+i+'][unita]" class="form-control" /<td><td><input type="text" name="addmore['+i+'][quantita]" class="form-control" /></td><td><button type="button" class="btn btn-danger remove-tr">Rimuovi</button></td></tr>');
            });

            $(document).on('click', '.remove-tr', function(){
                $(this).parents('tr').remove();
            });
        </script>
 <table class="table-responsive" id="dynamicTable">
                    <tr>
                        <th>Descrizione</th>
                        <th>Marca</th>
                        <th>Modello</th>
                        <th>Unità</th>
                        <th>Quantità</th>
                    </tr>
                    <tr>
                        <td><input type="text" name="addmore[0][desc_art]" class="form-control" /></td>
                        <td><input type="text" name="addmore[0][marca]" class="form-control" /></td>
                        <td><input type="text" name="addmore[0][modello]" class="form-control" /></td>
                        <td><input type="text" name="addmore[0][unita]" class="form-control" /></td>
                        <td><input type="number" name="addmore[0][quantita]" class="form-control" /></td>
                        <td><button type="button" name="add" id="add" class="btn btn-primary">Aggiungi</button></td>
                    </tr>
                </table>
                <button type="submit" id="dynamicTable" class="btn btn-primary ">Salva</button>
            </form>
        </div>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source