-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Start
Get up and running with Romega Software - Availability in 5 minutes.
Add the HasAvailability trait to any Eloquent model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use RomegaSoftware\Availability\Traits\HasAvailability;
class Room extends Model
{
use HasAvailability;
}Let's make a room available on weekdays only:
use RomegaSoftware\Availability\Support\Effect;
$room = Room::find(1);
$room->availabilityRules()->create([
'type' => 'weekdays',
'config' => ['days' => [1, 2, 3, 4, 5]], // Monday to Friday
'effect' => Effect::Allow,
'priority' => 10,
'enabled' => true,
]);use RomegaSoftware\Availability\Support\AvailabilityEngine;
$engine = app(AvailabilityEngine::class);
// Check if available now
if ($engine->isAvailable($room, now())) {
echo "Room is available!";
} else {
echo "Room is not available.";
}
// Check for a specific time
$nextMonday = now()->next('Monday')->setTime(14, 0);
if ($engine->isAvailable($room, $nextMonday)) {
echo "Room is available next Monday at 2 PM!";
}Here's a full example for a meeting room booking system:
<?php
use App\Models\Room;
use RomegaSoftware\Availability\Support\AvailabilityEngine;
use RomegaSoftware\Availability\Support\Effect;
// Get a room
$room = Room::find(1);
// Set default to deny (room is not available by default)
$room->availability_default = Effect::Deny;
$room->availability_timezone = 'America/New_York';
$room->save();
// Make room available Mon-Fri
$room->availabilityRules()->create([
'type' => 'weekdays',
'config' => ['days' => [1, 2, 3, 4, 5]],
'effect' => Effect::Allow,
'priority' => 10,
'enabled' => true,
]);
// But only during business hours
$room->availabilityRules()->create([
'type' => 'time_of_day',
'config' => ['from' => '09:00', 'to' => '17:00'],
'effect' => Effect::Allow,
'priority' => 20,
'enabled' => true,
]);
// Block out holidays
$room->availabilityRules()->create([
'type' => 'blackout_date',
'config' => ['dates' => ['2025-12-25', '2025-01-01']],
'effect' => Effect::Deny,
'priority' => 30, // Higher priority overrides previous rules
'enabled' => true,
]);
// Check availability
$engine = app(AvailabilityEngine::class);
$checkTime = \Carbon\Carbon::parse('2025-01-15 10:30:00', 'America/New_York');
if ($engine->isAvailable($room, $checkTime)) {
echo "Room can be booked for this time!";
}-
Effect::Allow- Makes the resource available -
Effect::Deny- Makes the resource unavailable
- Lower numbers are evaluated first
- Higher numbers are evaluated last
- Last matching rule wins
// Priority 10: Weekdays → Allow
// Priority 20: After 5 PM → Deny
// If it's Monday at 6 PM, the room is NOT available (priority 20 wins)- Basic Usage - More examples and patterns
- Rule Types - Explore all available rule types
- How It Works - Deep dive into the evaluation engine
Romega Software is software development agency specializing in helping customers integrate AI and custom software into their business, helping companies in growth mode better acquire, visualize, and utilize their data, and helping entrepreneurs bring their ideas to life.
Installation
Set up the package in your Laravel app
Quick Start
Get running in 5 minutes
Basic Usage
Common patterns and examples
How It Works
Understanding the evaluation engine
Rule Types
Available rule types and configurations
Priority System
How rule priority affects evaluation
Inventory Gates
Dynamic availability based on stock
Custom Evaluators
Build your own rule types
Complex Scenarios
Real-world implementation patterns
Performance Tips
Optimization strategies
Configuration
Package configuration options
Models & Traits
Available models and traits
Testing
Testing your availability rules