1. Go to this page and download the library: Download solution-forest/bookflow library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
solution-forest / bookflow example snippets
// Set capacity for your model
class Room extends Model
{
use HasBookings;
public $capacity = 3; // Allow 3 bookings per timeslot
}
// Multiple users can book the same time
$booking1 = Booking::create([...]); // Uses 1/3 capacity
$booking2 = Booking::create([...]); // Uses 2/3 capacity
$booking3 = Booking::create([...]); // Uses 3/3 capacity
// 4th booking would throw BookingException
// Check availability
$available = $room->isAvailable($start, $end, null, $quantity);
// In config/bookflow.php
'booking' => [
'default_capacity' => 3, // Change default capacity for all models
]
return [
'pricing' => [
'strategies' => [
'fixed' => \SolutionForest\Bookflow\Services\PricingStrategies\FixedPriceStrategy::class,
'hour' => \SolutionForest\Bookflow\Services\PricingStrategies\TimeBasedPricingStrategy::class,
'day' => \SolutionForest\Bookflow\Services\PricingStrategies\TimeBasedPricingStrategy::class,
],
'custom_strategies' => [
// Add your custom strategies here
// 'group' => \App\Services\PricingStrategies\GroupBookingStrategy::class,
],
'time_based' => [
'round_up' => true, // Whether to round up partial units
'minimum_units' => 1, // Minimum number of units to charge
],
],
];
use SolutionForest\Bookflow\Traits\HasBookings;
class Room extends Model
{
use HasBookings;
// Your model implementation
}
use SolutionForest\Bookflow\Models\Booking;
// Create a booking using the fluent interface
$booking = Booking::make()
->forRate($hourlyRate)
->from(now())
->to(now()->addHours(3))
->forCustomer($customer)
->forBookable($room)
->withQuantity(2)
->withNotes('Special 'bookable_type' => Room::class,
'quantity' => 1,
]);
// Check booking status
$isPast = $booking->isPast();
$isCurrent = $booking->isCurrent();
$isFuture = $booking->isFuture();
$isCancelled = $booking->isCancelled();
// Get related bookings
$pastBookings = $booking->past();
$currentBookings = $booking->current();
$futureBookings = $booking->future();
$cancelledBookings = $booking->cancelled();
use SolutionForest\Bookflow\Helpers\BookingHelper;
// Check if a room is available for a specific time period
$room = Room::find(1);
$isAvailable = $room->isAvailable(
start: now(),
end: now()->addHours(2)
);
// Get all available rates for a time period
$availableRates = $room->getAvailableRates(
start: now(),
end: now()->addHours(2)
);
// Find available time slots
$timeSlots = BookingHelper::findAvailableTimeSlots(
bookable: $room,
date: now()->toDateString(),
duration: 60, // minutes
rate: $hourlyRate // optional: filter by specific rate
);
// Advanced availability checking
$availability = BookingHelper::checkAvailability(
bookable: $room,
start: now(),
end: now()->addDays(7),
rate: $hourlyRate,
quantity: 2 // check if multiple units are available
);
// Get conflicting bookings
$conflicts = $room->getConflictingBookings(
start: now(),
end: now()->addHours(2)
);