我想知道是否有人已经解决了我的问题。 我使用Laravel 5 Full Calendar Helper来创建预订应用程序。 我想要实现的是在特定日期(即预订日期)呈现日历 例如,如果有人想在2015年12月31日预订房间,他将能够在预订房间之前查看该日期(日视图)上的日历。
到目前为止我得到了这个
ConsultController
<?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();
}
}
}
我有这个观点
但我想要的是这个观点
答案 0 :(得分:2)
对文档进行详细审查后我发现这个帮助器类有一个setOptions方法,允许在渲染日历时有更多的控制权
我刚刚添加了这个方法并达到了我想要的目标
$calendar = \Calendar::addEvents($events)->setOptions([ 'defaultDate' => $book->day,'defaultView' => 'agendaDay']);