Skip to content

Quick Start

Braden Keith edited this page Sep 20, 2025 · 1 revision

Quick Start

Get up and running with Romega Software - Availability in 5 minutes.

Step 1: Add Availability to Your Model

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;
}

Step 2: Create Your First Rule

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,
]);

Step 3: Check Availability

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!";
}

Complete Working Example

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!";
}

Understanding the Basics

Effects

  • Effect::Allow - Makes the resource available
  • Effect::Deny - Makes the resource unavailable

Priority

  • Lower numbers are evaluated first
  • Higher numbers are evaluated last
  • Last matching rule wins

Example Priority Flow

// 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)

What's Next?

Getting Started

Installation
Set up the package in your Laravel app

Quick Start
Get running in 5 minutes

Basic Usage
Common patterns and examples


Core Concepts

How It Works
Understanding the evaluation engine

Rule Types
Available rule types and configurations

Priority System
How rule priority affects evaluation


Advanced Topics

Inventory Gates
Dynamic availability based on stock

Custom Evaluators
Build your own rule types

Complex Scenarios
Real-world implementation patterns

Performance Tips
Optimization strategies


API Reference

Configuration
Package configuration options

Models & Traits
Available models and traits

Testing
Testing your availability rules

Clone this wiki locally