1. Go to this page and download the library: Download cheesytech/booking 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/ */
use CheeasyTech\Booking\Contracts\Bookable;
use CheeasyTech\Booking\Traits\HasBookings;
use Illuminate\Database\Eloquent\Model;
class Room extends Model implements Bookable {
use HasBookings;
// ...
public function getBookableId(): int { return $this->id; }
public function getBookableType(): string { return static::class; }
}
use CheeasyTech\Booking\Contracts\Bookerable;
use CheeasyTech\Booking\Traits\HasBookers;
class User extends Model implements Bookerable {
use HasBookers;
// ...
public function getBookerableId(): int|string { return $this->id; }
public function getBookerableType(): string { return static::class; }
}
use CheeasyTech\Booking\Models\Booking;
use Carbon\Carbon;
$room = Room::find(1);
$user = User::find(1);
$booking = new Booking();
$booking->bookable()->associate($room);
$booking->bookerable()->associate($user);
$booking->start_time = Carbon::tomorrow()->setHour(10);
$booking->end_time = Carbon::tomorrow()->setHour(11);
$booking->status = 'pending';
$booking->save();
// Change booking status
$booking->changeStatus('confirmed', 'Approved by admin', ['key' => 'value']);
// Check for overlap
$isAvailable = !$booking->hasOverlap(
Carbon::tomorrow()->setHour(10),
Carbon::tomorrow()->setHour(11)
);
// Get bookings longer than 2 hours
Booking::durationLongerThan(120)->get();
// Get bookings between 1 and 2 hours
Booking::durationBetween(60, 120)->get();
// Combine with other conditions
Booking::durationLongerThan(120)->where('status', 'confirmed')->get();
$booking->changeStatus('confirmed', 'Approved by supervisor', ['approver_id' => 123]);
$status = $booking->getCurrentStatus();
$history = $booking->getStatusHistory();
if ($booking->hasStatus('confirmed')) { /* ... */ }