我想知道是否有人已经解决了我的问题。 我正在使用 Laravel 5 Full Calendar Helper 来创建预订应用程序。 我想要实现的是在特定日期(即预订日期)呈现日历 例如,如果有人想预订 2015 年 12 月 31 日的房间,他将能够在预订房间之前看到该日期的日历(日 View )。
到目前为止我已经得到了这个
咨询 Controller
<?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();
}
}
}
我有这个观点
但我想要的是这个 View
最佳答案
详细查看文档后,我发现这个辅助类有一个 setOptions 方法,可以在渲染日历时进行更多控制
我刚刚添加了该方法并达到了我想要的效果
$calendar = \Calendar::addEvents($events)->setOptions([ 'defaultDate' => $book->day,'defaultView' => 'agendaDay']);
关于fullcalendar - 使用 FullCalendar 包打开特定日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34424847/