Introduction

Acorn MilliRules brings the MilliRules Engine into your Acorn application. It adds route-aware conditions, HTTP response actions, CLI commands, and automatic rule discovery — everything you need to define and manage rules that react to Laravel routes.

What This Package Provides#Copied!

  • Route-aware conditions — match rules by route name, route parameters, or controller class
  • HTTP response actions — redirect requests or set response headers
  • Route context — automatic context loading with route metadata (name, parameters, controller, URI, middleware)
  • 8 Artisan commands — list, inspect, and scaffold rules, actions, and conditions
  • Auto-discovery — rule classes in app/Rules/ are registered automatically
  • Middleware integration — rules execute after route matching with zero configuration
Note: This package extends MilliRules with Acorn-specific features. For general concepts like rules, conditions, actions, operators, and the fluent builder API, see the MilliRules documentation.

Prerequisites#Copied!

Requirement Version
PHP >= 8.1
Roots Acorn ^4.0 or ^5.0
MilliRules ^0.7 (auto-installed)

MilliRules is declared as a Composer dependency and will be installed automatically. You do not need to install it separately.

How It Works#Copied!

The execution flow in Acorn follows these steps:

  1. Service provider bootsServiceProvider initializes MilliRules, registers the Acorn package, and discovers your rule classes
  2. Auto-discovery — rule classes in app/Rules/*.php are instantiated and their register() method is called, which registers rules with the engine
  3. Request arrives — Laravel routes the request to a controller as usual
  4. Middleware executes — the ExecuteRules middleware runs after the controller, so route context (name, parameters, controller) is available
  5. Rules evaluate — MilliRules evaluates all registered rules against the current context
  6. Response modified — actions collect response modifications (headers, redirects) via the ResponseCollector, and the middleware applies them to the outgoing HTTP response
Tip: The builder API supports both camelCase (->routeName(), ->setHeader()) and snake_case (->route_name(), ->set_header()) method names. This documentation uses camelCase to align with Laravel conventions, but both styles work identically.

Next Steps#Copied!


Ready to get started? Continue to the Installation guide.