使用FullCalendar软件包打开特定日期
我想知道是否有人已经解决了我的问题。 我正在使用Laravel 5 Full Calendar Helper创建预订应用程序。 我想要实现的是在预定日期的特定日期呈现日历 例如,如果有人想预订2015年12月31日的房间,他将能够在预订房间之前查看该日期的日历(日视图) 到目前为止,我得到了这个 顾问控制员使用FullCalendar软件包打开特定日期,fullcalendar,laravel-5.1,Fullcalendar,Laravel 5.1,我想知道是否有人已经解决了我的问题。 我正在使用Laravel 5 Full Calendar Helper创建预订应用程序。 我想要实现的是在预定日期的特定日期呈现日历 例如,如果有人想预订2015年12月31日的房间,他将能够在预订房间之前查看该日期的日历(日视图) 到目前为止,我得到了这个 顾问控制员 <?php namespace App\Http\Controllers; use App\Booking; use App\Http\Requests\BookingReques
<?php
namespace App\Http\Controllers;
use App\Booking;
use App\Http\Requests\BookingRequest;
use App\Room;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
class ConsultController extends Controller
{
public function consult(BookingRequest $request){
// Look for the booking which matches with our search
$seek = Booking::where('room_id','=',$request->room)
->where('day','=',$request->day)
->where('start','=',$request->start)->first();
// If no booking matches, then book
if(is_null($seek)){
$book = $request;
// Get all the bookings on day requested
$bookings = Booking::where('day','=',$request->day)->get();
// creating events for the calendar
$events = [];
foreach($bookings as $booking){
$events[] = \Calendar::event(
''.$booking->room->name, //event title
false, //full day event?
$booking->day->format('Y-m-d').$booking->start, //start time (you can also use Carbon instead of DateTime)
$booking->day->format('Y-m-d').$booking->end, //end time (you can also use Carbon instead of DateTime)
$booking->id //optionally, you can specify an event ID
);
}
$events [] = \Calendar::event(
''.Room::find($book->room)->name, //event title
false,
$book->day.$book->start,
$book->day.$book->end,
0,
[
'backgroundColor' => '#ff5722'
]
);
// Adding event for the calendar
$calendar = \Calendar::addEvents($events);
return view('consult.book')->with(['calendar' => $calendar,'book'=>$book]);
}
// If a record matches then redirect back
else{
Session::flash('flash_message','Lo sentimos ese horario está ocupado');
return redirect()->back();
}
}
}
详细查看文档后,我发现这个helper类有一个setOptions方法,可以在呈现日历时进行更多控制
我只是添加了这个方法,达到了我想要的效果
$calendar = \Calendar::addEvents($events)->setOptions([ 'defaultDate' => $book->day,'defaultView' => 'agendaDay']);