Laravel Rulebook: Business Rules That Change by Date
Laravel Rulebook offers a clean architecture for managing time-sensitive business logic, such as holiday pricing, tax adjustments, and regulatory cutoffs, without messy conditional code.
Managing Temporal Business Logic with Laravel Rulebook
When business rules change on a specific dateāsuch as tax rate increases, holiday promotional discounts, or new compliance regulationsācontrollers often become cluttered with messy date comparisons:
// The messy approach:
if (now()->between($blackFridayStart, $blackFridayEnd)) {
$discount = 0.25;
} elseif (now()->isAfter($q4Cutoff)) {
$discount = 0.15;
}
The Rulebook Architecture
Laravel Rulebook introduces a clean, declarative approach to time-sensitive policy modeling:
namespace App\Rules\Pricing;
use LaravelRulebook\Rule;
class HolidayDiscountRule extends Rule
{
public function effectiveDate(): string
{
return '2026-11-25 to 2026-12-02';
}
public function apply($cart): void
{
$cart->discountPercentage = 25;
}
}
Rulebook allows querying and testing rules against past, present, or future dates without touching system clocks.