Reputation: 39
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>{{$slot->date}}</td>
<td>{{$slot->time}}</td>
<td>
<input name="id" value="{{$slot->id}}" 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', GET DATE ID)
->update(['status' => 1]);
$booking->save();
return redirect('/bookings')->with([
'success' => 'Booking successful!',
]);
}
Upvotes: 1
Views: 9271
Reputation: 7509
from the docs
$request->all();
or
$request->get('filedName');
or
$request->fieldName;
or
$request->input('fieldName');
These are the ways of getting inputs including hidden ones
Upvotes: 0
Reputation: 751
In store function you are Typehinting Request.
store(Request $request)
The first Request is referring to the request handler. So if you'll put this after your.
$booking->date_id = $request->input('id')
Thats your answer.
You are requesting the input id from the request input
Upvotes: 0
Reputation: 2101
Use the request object to retrieve the parameters you send :
$whatYouNeed = $request->id
(or in general $request->WhateverYouNamedYourField
)
Edit : This is not related to hidden fields only, it works with any kind of form fields.
Upvotes: 3