2015-12-22 71 views
2

我想知道是否有人已經解決了我的問題。 我正在使用Laravel 5 Full Calendar Helper創建預訂應用程序。 我想要實現的是在預訂日期的特定日期呈現日曆 例如,如果有人想爲2015年12月31日預訂房間,他將能夠在該日期(日期查看),然後預訂他們的房間。使用FullCalendar包打開特定日期

到目前爲止,我得到這個

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(); 
     } 

    } 
} 

我有這種說法

enter image description here

,但我要的是這種觀點

enter image description here

回答

2

以詳細審查我發現的文件,這個助手類有一個setOptions方法,它允許有更多的控制渲染日曆時

我剛添加的方法,達到什麼我正在尋找

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