Reputation: 33
I've looked everywhere and really not so sure if this is possible.
I have an inline datepicker with an altField and I want the selected date to be inserted into the database. The $service_id, $service_name and $service_price are passed in.
I know I'm doing something wrong, hence why I would like to ask for some advice here.
Here's some of my show.blade.php contents
<script>
$(function () {
$("#datepicker").datepicker({
// showOtherMonths: true,
// selectOtherMonths: true,
// numberOfMonths: 2,
firstDay: 1,
altField: "#dateofbooking",
altFormat: "yy-mm-dd",
minDate: 0,
maxDate: "+2W",
});
});
</script>
<div class="row">
<div class="col-sm-7 text-center">
<div id="datepicker" class="text-center"></div>
</div> <!-- col-sm-8 end -->
<div class="col-sm-1">
</div>
<div class="col-sm-4">
{!! Form::open(['action' => 'PagesController@storebooking', 'method' => 'POST']) !!}
<div class="form-group"></br>
<h3 class="text-center">Selected Service</h3>
<hr class="featurette-divider">
<h4 class="float-left">{{$service_name}}</h4>
<h4 class="float-right">£ {{$service_price}}</h4>
<br>
{{Form::hidden('service_id', $service_id, ['class' => 'form-control', 'placeholder' => 'Service ID'])}}
{{Form::hidden('service_name', $service_name, ['class' => 'form-control', 'placeholder' => 'Service Name'])}}
{{Form::hidden('service_price', $service_price, ['class' => 'form-control', 'placeholder' => 'Service Price'])}}
</div>
<div class="form-group"></br>
<h3>Selected Date:</h3>
<!-- This will be hidden -->
{{Form::text('dateofbooking', '', ['id' => 'dateofbooking', 'class' => 'form-control', 'placeholder' => 'Booking Date'])}}
</div>
{{Form::submit('Book Appointment', ['class' => 'submitbtn btn btn-primary btn-lg btn-block', 'style' => 'border-radius: 20px;'])}}
{!! Form::close() !!}
</div>
</div> <!-- col-sm-4 end -->
</div> <!-- div row end -->
@endsection
What I'm using to store the information
public function storebooking(Request $request)
{
$services = new Service;
$bookings = new Booking;
$bookings->user_id = auth()->user()->id;
$bookings->username = auth()->user()->username;
$bookings->firstname = auth()->user()->firstname;
$bookings->surname = auth()->user()->surname;
$bookings->email = auth()->user()->email;
$bookings->service_id = $request->input('service_id');
$bookings->service_name = $request->input('service_name');
$bookings->service_price = $request->input('service_price');
// $booking->dateofbooking = $request->input('dateofbooking'); // Doesn't work
$bookings->save();
return redirect('history')->with('success', 'Appointment Booked');
}
Upvotes: 0
Views: 169
Reputation: 33
Thanks to MGS for helping me troubleshoot and come up with the solution.
For anyone else having any problems, this solved my issue:
show.blade.php
{{Form::hidden('dateofbooking', '', ['id' => 'dateofbooking'])}}
and used this in function storebooking
$bookings->dateofbooking = $request->input('dateofbooking');
Upvotes: 1