fullcalendar - 使用 FullCalendar 包打开特定日期

标签 fullcalendar laravel-5.1

我想知道是否有人已经解决了我的问题。 我正在使用 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();
        }

    }
}

我有这个观点

enter image description here

但我想要的是这个 View

enter image description here

最佳答案

详细查看文档后,我发现这个辅助类有一个 setOptions 方法,可以在渲染日历时进行更多控制

我刚刚添加了该方法并达到了我想要的效果

$calendar = \Calendar::addEvents($events)->setOptions([ 'defaultDate' => $book->day,'defaultView' => 'agendaDay']);

关于fullcalendar - 使用 FullCalendar 包打开特定日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34424847/

相关文章:

Laravel 在毫秒时间戳内获取 create_at

php - 在 Laravel 5.1 分页中使用漂亮的 URL

php - 如何仅显示 Laravel Blade 模板中集合中的第一项的内容

javascript - Fullcalendar (v2.x) 从 eventClick 获取日期单元格?

javascript - 通过 servlet 将数据库中的数据显示到 fullcalendar - 未列出事件

javascript - 全日历 : Ignore events during select

css - 在 Full Calendar 2.3.2 中更改标题标题颜色

twitter-bootstrap - 带有 Ember 和 Twitter Bootstrap 的 FullCalendar

Laravel 5 Socialite 如何发送重新请求 (auth_type=rerequest) 到 Facebook

mysql - Laravel 查询生成器 - 从 MySQL 获取当前时间