mardi 22 décembre 2015

Open a specific day using FullCalendar package

I wonder if someone has already figured my problem out. I'm using Laravel 5 Full Calendar Helper in order to create a booking app. What I want to achieve is to render the calendar on an specific day which is the booking date For example if someone wants to book a room for 12/31/2015, he will be able to see the calendar on that date (day view), before book their room.

So far I got this

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

    }
}

I have this view

enter image description here

but what I want is this view

enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire