Routing Laravel 5.7 Fullcalendar-Day使用参数单击路线
当我点击Fullcalendar中的某一天时,我会尝试传递一个带有参数的链接(例如route('reservation.create')。参数是“verhicle\u id”、“user\u id”和date 我有以下代码(reservationController): index.blade.phpRouting Laravel 5.7 Fullcalendar-Day使用参数单击路线,routing,fullcalendar,crud,materialize,laravel-5.7,Routing,Fullcalendar,Crud,Materialize,Laravel 5.7,当我点击Fullcalendar中的某一天时,我会尝试传递一个带有参数的链接(例如route('reservation.create')。参数是“verhicle\u id”、“user\u id”和date 我有以下代码(reservationController): index.blade.php @extends('layouts.app') @section('content') <div class="section container"> <h1>
@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
@extends('layouts.app'))
@节(“内容”)
历法
@端部
@节(“脚本”)
风险值数据=[
@foreach($reservationas$reservation)
{
标题:“{{$reservation->vehicle->name}”,
开始:“{{$reservation->start_date}}”,
说明:{{$reservation->vehicle->location->name}}
从{{{$reservation->user->name}预订,
颜色:“{{$reservation->vehicle->color}”,
url:“{route('reservations.edit',$reservation->id)}”
},
@endforeach
];
$(文档).ready(函数(){
//页面现在已准备就绪,请初始化日历。。。
$(“#日历”).fullCalendar({
//把你的选择和回电放在这里
事件:数据,
dayClick:函数(日期、全天、jsEvent、视图){
//我想在这里链接到CRUD reservations.create,参数为vehicle\u id、user\u id和单击的日期
},
eventRender:函数(事件,元素){
元素。工具提示({
位置:'顶部',
html:event.title+“
”+event.description,
触发器:“悬停”
});
}
});
});
@端部
但我没有关于此代码中车辆id和用户id的信息或访问权限。
我必须如何自定义接收此信息的代码。
我不想让它在模态
我之所以要这样做,是因为用户不再需要在创建表单中指定此数据(是隐藏字段)
对不起,我的英语很差。我希望每个人都能帮助我。
当做
迪米:谢谢你的评论 我对我的问题有一个解决方案。它对我来说很好。但它对我来说是一个原型 reservationsController:
public function booking($id) {
$reservations = Reservation::where('vehicle_id', $id)->get();
return view('reservations.index')->with('reservations', $reservations);
}
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]);
}
php(我在materialize中使用了modal)
@extends('layouts.app'))
@节(“内容”)
历法
创建预订
@csrf
预算1
预算2
预算3
预算
提交
@端部
@节(“脚本”)
风险值数据=[
@foreach($reservationas$reservation)
{
标题:“{{$reservation->vehicle->name}”,
开始:“{{$reservation->start_date}}”,
说明:{{$reservation->vehicle->location->name}}
Reserviert:{{{$reservation->user->name}}
座位:{{{$reservation->vehicle->Seats}},
颜色:“{{$reservation->vehicle->color}”,
url:“{route('reservations.edit',$reservation->id)}”
},
@endforeach
];
$(文档).ready(函数(){
@isset(车辆ID)
var vehicleid={{$vehicleid};
@尾端集
@isset($userid)
var userid={{$userid}};
@尾端集
//页面现在已准备就绪,请初始化日历。。。
$(“#日历”).fullCalendar({
//把你的选择和回电放在这里
事件:数据,
dayClick:函数(日期、全天、jsEvent、视图){
//上面我在表单隐藏字段中填充了值
$(#vehicleid').val(vehicleid);
$('#userid').val(userid);
$('#date').val(date.format());
$('#modal1').modal('open');
$('.trigger modal').modal();
},
eventRender:函数(事件,元素){
元素。工具提示({
位置:'顶部',
html:event.title+“
”+event.description,
触发器:“悬停”
});
}
});
});
@端部
如果有人有更好的解决方案,请告诉我。
当做
Dimi您可以使用PHP代码将数据写入页面中的隐藏字段中。然后,当dayClick运行时,从隐藏字段中获取这些值,并将它们用作表单链接中的参数。
@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