我只是在全天单击fullcalendar的一天时尝试,我在带有参数的链接(示例路由('Reservery.Create')中。参数为" verhicle_id"," user_id"和日期。
我有以下代码(ReservationController):
public function booking($id) {
$reservations = Reservation::where('vehicle_id', $id)->get();
return view('reservations.index')->with('reservations', $reservations);
}
index.blade.php
@extends('layouts.app')
@section('content')
<div class="section container">
<h1>Calendar</h1>
<div id="calendar" class="tooltipped"></div>
</div>
@endsection
@section('scripts')
var data = [
@foreach($reservations as $reservation)
{
title : '{{ $reservation->vehicle->name }}',
start : '{{ $reservation->start_date }}',
description: '{{ $reservation->vehicle->location->name }} <br>Reservation from: {{ $reservation->user->name }}',
color: '{{ $reservation->vehicle->color }}',
url : '{{ route('reservations.edit', $reservation->id) }}'
},
@endforeach
];
$(document).ready(function() {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
// put your options and callbacks here
events: data,
dayClick: function(date, allDay, jsEvent, view) {
//here I want to link to CRUD reservations.create with parameter vehicle_id, user_id and date clicked
},
eventRender: function (event, element) {
element.tooltip({
position: 'top',
html: event.title + "<br>" + event.description,
trigger: 'hover'
});
}
});
});
@endsection
但是我在此代码中没有有关warter_id和user_id的信息或访问。我将如何自定义我收到此信息的代码。我不想这样做。
我要这样做的原因是,用户不再需要在创建形式中指定此数据(隐藏场)。
对不起,我的英语不好。希望每个人都能帮助我。问候dimi
@adyson:感谢您的评论。
我对我的问题有一个解决方案。对我有用。但这是我的原型。
Reservations Controller:
public function booking($id)
{
$user_id = 2;
$reservations = Reservation::where('vehicle_id', $id)->get();
return view('reservations.index')->with(['reservations' => $reservations, 'vehicleid' => $id, 'userid' => $user_id]);
}
public function store(Request $request)
{
$reservation = new Reservation;
$reservation->user_id = $request->input('userid');
$reservation->vehicle_id = $request->input('vehicleid');
$reservation->budget_id = $request->input('budget');
$reservation->start_date = $request->input('date');
$reservation->end_date = $request->input('date');
$reservation->save();
return redirect()->route('reservations.booking', ['id' => $reservation->vehicle_id]);
}
index.blade.php(我与Modal in positalize合作)
@extends('layouts.app')
@section('content')
<div class="section container">
<h1>Calendar</h1>
<div id='calendar' class="tooltipped"></div>
<a class="waves-effect waves-light btn modal-trigger" href="#modal1">Modal</a>
<!-- Modal Structure -->
<div id="modal1" class="modal">
<div class="modal-content">
<h1>Create Reservation</h1>
<form class="col s6" action="{{route('reservations.store')}}" method="POST">
@csrf
<div class="input-field col s12">
<select name="budget">
<option value="1">Budget 1</option>
<option value="2">Budget 2</option>
<option value="3">Budget 3</option>
</select>
<label>Budget</label>
</div>
<input readonly value="" name="vehicleid" id="vehicleid" type="hidden">
<input readonly value="" name="userid" id="userid" type="hidden">
<input readonly value="" name="date" id="date" type="hidden">
</div>
<div class="modal-footer">
<button class="btn waves-effect waves-light" type="submit" name="action">Submit
</button>
</form>
</div>
</div>
</div>
@endsection
@section('scripts')
var data = [
@foreach($reservations as $reservation)
{
title : '{{ $reservation->vehicle->name }}',
start : '{{ $reservation->start_date }}',
description: '{{ $reservation->vehicle->location->name }} <br>Reserviert: {{ $reservation->user->name }} <br>Seats: {{ $reservation->vehicle->seats }} ',
color: '{{ $reservation->vehicle->color }}',
url : '{{ route('reservations.edit', $reservation->id) }}'
},
@endforeach
];
$(document).ready(function() {
@isset($vehicleid)
var vehicleid = {{$vehicleid}};
@endisset
@isset($userid)
var userid = {{$userid}};
@endisset
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
// put your options and callbacks here
events: data,
dayClick: function(date, allDay, jsEvent, view) {
// above I filled the value in the form hidden fields
$('#vehicleid').val(vehicleid);
$('#userid').val(userid);
$('#date').val(date.format());
$('#modal1').modal('open');
$('.trigger-modal').modal();
},
eventRender: function (event, element) {
element.tooltip({
position: 'top',
html: event.title + "<br>" + event.description,
trigger: 'hover'
});
}
});
});
@endsection
如果有人有更好的解决方案,请告诉我。问候dimi