1 year ago

laravel update without passing ID

Posted 1 year ago by woxene

I am working on a ticket log where tickets get edited multiple times before they are 'done'.

I have an overview where you see all the tickets, on top of the page are 6 buttons. All buttons open a popup with a form. The first button is a create function which makes the ticket and fills in the first information. All other fields are now NULL. The second buttons is the first edit button.

Upon opening it opens an form where the user scans a barcode to fill in the first field; Ticket Number. this ticket number is unique for every Ticket. Next thing to fill in is your credentials, which come from a dropdown.

Due to the fact that all the edit forms work by Ticket_number (which is scanned from a QR code) I made it so all forms are on the same page. Therefor I am not able to do something like : action="{{ route('countries.update',$country->id) }} as I don't know the ID at this moment.

Here is the code behind everything(and you can see what I tried there too):


     Route::post('ticket/start-picking', '[email protected]')->name('tickets.startpicking');
     Route::resource('tickets', 'TicketController');

form for edit:

    <div id="modal-start-picking" class="modal">
        <form method="POST" id="modal-start-picking-form" action="{{ route('tickets.startpicking') }}">
            <input type="text" value="modal-start-picking" name="type" hidden>
            <div class="modal-content">
                <h4>Start Picking</h4>
                <p>Scan Ticket Number here</p>
                <div class="input-field">
                    <label for="start">Ticket Number</label>
                    <input type="text" name="ticket_number" id="start" autofocus>
                <div class="input-field">
                    <select id="picker" name="picker">
                        <option value="" disabled selected>Choose a Picker</option>
                        @foreach($employees as $employee)
                            <option {{(old('picker') == $employee->initials ) ? 'selected' : ''}} value="{{ $employee->initials }}">{{ $employee->initials }}</option>
            <div class="modal-footer">
                <input class="btn-flat" type="submit" value="Start Picking">

Function in TicketController:

    public function startpicking(Request $request, Ticket $ticket)
            'picker' => 'required',
        $ticket->update(array_merge($request->all(), ['picker_start_time' => Carbon::now()]));
        return redirect()->route('tickets.index')->with('toast', 'Ticket updated successfully');

If any more info is required I Will gladly update my post.

Please sign in or create an account to participate in this conversation.