vendredi 9 février 2018

Laravel 5.5: Send value of hidden form input to controller

In my view, I'm getting all the available slots so a user can click the book button to book that slot. However, I just can't seem to find a way to get the correct value (id of the input) so I can set the status of the specific booking in the database to booked.

index.blade.php

@if(count($slots) > 0)
                            <table class="table table-striped">
                                <tr>
                                    <th>Date</th>
                                    <th>Time</th>
                                    <th></th>
                                </tr>
                                @foreach($slots as $slot)
                                    <tr>
                                        <td></td>
                                        <td></td>
                                        <td>
                                            <input name="id" value="" type="hidden"> THIS IS WHAT I WANT TO SEND
                                            <button class="btn btn-primary pull-right" type="submit">Book</button>
                                        </td>
                                    </tr>
                                @endforeach

BookingsController.php

public function store(Request $request)
    {
        $booking = new Booking;
        $booking->user_id = auth()->user()->id;
        $booking->date_id = THIS IS WHAT I NEED;

                    DB::table('calendar')
                            ->select('id','status')
                            ->where('id', $dateid)
                            ->update(['status' => 1]);          
        $booking->save();



        return redirect('/bookings')->with([
                'success' => 'Booking successful!',
        ]);
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire