Hi @peterbrinck thanks
this is my FullCalendarController
Hi @peterbrinck ,
this is my FullCalendarController:
Controller:
public static function getBookingByRoomId($id)
{
$booking = Booking::where('room_id', '=', $id)
->orderBy('start_date')
->get([
'booked_by',
'start_date',
'end_date',
]);
return $booking->map(function($event) {
$booking['title'] = 'Booked by ' . $event->user->name;
$booking['start'] = $event->start_date->toDateTimeString();
$booking['end'] = $event->end_date->toDateTimeString();
return $booking;
});
}
public static function getBookingAllRoom()
{
$booking = Booking::orderBy('start_date')
->get([
'id',
'room_id',
'booked_by',
'start_date',
'end_date',
]);
// return $booking;
return $booking->map(function($event) {
$booking['id'] = $event->room_id;
$booking['resourceId'] = $event->room_id;
$booking['start'] = $event->start_date->toDateTimeString();
$booking['end'] = $event->end_date->toDateTimeString();
$booking['title'] = $event->user->name;
return $booking;
});
}
public static function getRoomAll()
{
$room = Room::all();
return $room->map(function($event) {
$room['id'] = $event->id;
$room['title'] = $event->name;
$room['eventColor'] = 'red';
return $room;
});
}
Route:
Route::get('bookings/all', 'FullcalendarController@getBookingAllRoom')->name('fullcalendar.bookingall');
Route::get('rooms/all', 'FullcalendarController@getRoomAll')->name('fullcalendar.roomall');
Route::get('/fullcalendar', function () {
return view('dashboard.rooms-all');
});
Rooms-all.blade.php:
<style>
body {
margin: 0;
padding: 0;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
font-size: 14px;
}
#calendar {
max-width: 1024px;
margin: 50px auto;
}
</style>
$(function() {
$('#calendar').fullCalendar({
now: new Date(),
editable: false,
aspectRatio: 1.8,
scrollTime: '06:00',
defaultView: 'timelineDay',
views: {
timelineThreeDays: {
type: 'timeline',
duration: { days: 3 }
}
},
resourceLabelText: 'Rooms',
resources: '{!! route('fullcalendar.roomall') !!}',
// if active events it's no work
// events: '{!! route('fullcalendar.bookingall') !!}'
events: [
{
id: "1",
resourceId: "1",
start: "2018-06-27 09:00:00",
end: "2018-06-27 12:00:00",
title: "title1",
},
{
id: "2",
resourceId: "1",
start: "2018-06-27 15:00:00",
end: "2018-06-27 19:00:00",
title: "title2",
}
]
});
});