I am posting this in the Javascript section, but it is also a Laravel question.
I am trying to pass an array into the Flatpickr disable function, but it either does not seem to work at all or it only grabs the first date. Here are the two examples of what I have tried.
In my controller I do this to get them all:
`
public function render()
{
return view('livewire.booking-form',[
'durations' => Duration::all(),
'bookings' => Booking::all()->pluck('booked_date'),
]);
}
In the Flatpickr script:
`
document.addEventListener('alpine:init', () => {
Alpine.data('datepicker', () => ({
init() {
flatpickr(this.$refs.myDatePicker, {
// dateFormat: "m-d-Y",
disable: [
"{{$bookings}}"
],
});
}
}))
})
When I do a DD I see all the dates, but when I check on Flatpickr it only shows the first date disabled.
The second method I tried was this:
`
public function render()
{
return view('livewire.booking-form',[
'durations' => Duration::all(),
'bookings' => Booking::all(),
]);
}
` document.addEventListener('alpine:init', () => {
Alpine.data('datepicker', () => ({
init() {
flatpickr(this.$refs.myDatePicker, {
// dateFormat: "m-d-Y",
disable: [
],
@foreach($bookings as $booking )
data.push({ '{{ $booking->booked_date }}' });
@endforeach
});
}
}))
})
This method just seems to break flatpickr altogether. Any help is appreciated.