Conditions Reference
This is the complete reference for all conditions provided by the Acorn package. Each condition checks a value from the route context.
Route Name#Copied!
Match the current Laravel route name.
| Property | Value |
|---|---|
| Type | route_name |
| Class | MilliRulesAcornPackagesAcornConditionsRouteName |
| Context key | route.name |
| Operators | =, !=, LIKE, REGEXP, IN |
Builder Syntax#Copied!
1->routeName(string $value, string $operator = '=')
Examples#Copied!
Exact match:
1Rules::create('docs-show-header')
2 ->when()
3 ->routeName('docs.show')
4 ->then()
5 ->setHeader('X-Page', 'docs-show')
6 ->register();
Pattern match with LIKE (uses * as wildcard):
1Rules::create('all-docs-header')
2 ->when()
3 ->routeName('docs.*', 'LIKE')
4 ->then()
5 ->setHeader('X-Section', 'docs')
6 ->register();
Regular expression:
1Rules::create('docs-or-api-header')
2 ->when()
3 ->routeName('^(docs|api).', 'REGEXP')
4 ->then()
5 ->setHeader('X-App-Section', 'content')
6 ->register();
Match one of several values with IN:
1Rules::create('special-pages-header')
2 ->when()
3 ->routeName(['docs.show', 'docs.index', 'blog.show'], 'IN')
4 ->then()
5 ->setHeader('X-Content', 'true')
6 ->register();
Array Syntax#Copied!
1['type' => 'route_name', 'value' => 'docs.show']
2['type' => 'route_name', 'value' => 'docs.*', 'operator' => 'LIKE']
Route Parameter#Copied!
Check the value of a named route parameter. This is a name-based condition: the first argument is the parameter name, the second is the expected value.
| Property | Value |
|---|---|
| Type | route_parameter |
| Class | MilliRulesAcornPackagesAcornConditionsRouteParameter |
| Context key | route.parameters.{name} |
| Argument mapping | ['name', 'value'] |
| Operators | =, !=, LIKE, REGEXP, IN, EXISTS, NOT EXISTS |
Builder Syntax#Copied!
1// Existence check (parameter exists and is not empty)
2->routeParameter(string $name)
3
4// Value check
5->routeParameter(string $name, string $value, string $operator = '=')
Existence Check#Copied!
When only a parameter name is provided, the condition checks whether the parameter exists (is present and non-empty):
1Rules::create('has-product-param')
2 ->when()
3 ->routeParameter('product')
4 ->then()
5 ->setHeader('X-Has-Product', 'true')
6 ->register();
Explicitly check that a parameter does not exist:
1Rules::create('no-product-param')
2 ->when()
3 ->routeParameter('product', '', 'NOT EXISTS')
4 ->then()
5 ->redirect('/products')
6 ->register();
=) behaves like EXISTS — it checks actual !== ''.Value Check#Copied!
Compare the parameter value against an expected value:
1Rules::create('millicache-product')
2 ->when()
3 ->routeParameter('product', 'millicache')
4 ->then()
5 ->setHeader('X-Product', 'millicache')
6 ->register();
Pattern match:
1Rules::create('milli-products')
2 ->when()
3 ->routeParameter('product', 'milli*', 'LIKE')
4 ->then()
5 ->setHeader('X-Product-Family', 'milli')
6 ->register();
Regular expression:
1Rules::create('versioned-paths')
2 ->when()
3 ->routeParameter('path', '^v[0-9]+/', 'REGEXP')
4 ->then()
5 ->setHeader('X-Versioned', 'true')
6 ->register();
Array Syntax#Copied!
1// Existence check
2['type' => 'route_parameter', 'name' => 'product']
3
4// Value check
5['type' => 'route_parameter', 'name' => 'product', 'value' => 'millicache']
6
7// Pattern match
8['type' => 'route_parameter', 'name' => 'product', 'value' => 'milli*', 'operator' => 'LIKE']
Route Controller#Copied!
Match the fully qualified class name of the controller handling the current route.
| Property | Value |
|---|---|
| Type | route_controller |
| Class | MilliRulesAcornPackagesAcornConditionsRouteController |
| Context key | route.controller |
| Operators | =, !=, LIKE, REGEXP, IN |
Builder Syntax#Copied!
1->routeController(string $value, string $operator = '=')
Examples#Copied!
Exact match with the full class name:
1Rules::create('docs-controller-header')
2 ->when()
3 ->routeController('AppHttpControllersDocsController')
4 ->then()
5 ->setHeader('X-Handler', 'docs')
6 ->register();
Partial match with LIKE:
1Rules::create('any-api-controller')
2 ->when()
3 ->routeController('*Api*Controller', 'LIKE')
4 ->then()
5 ->setHeader('X-API', 'true')
6 ->register();
Match one of several controllers with IN:
1Rules::create('content-controllers')
2 ->when()
3 ->routeController([
4 'AppHttpControllersDocsController',
5 'AppHttpControllersBlogController',
6 ], 'IN')
7 ->then()
8 ->setHeader('X-Content', 'true')
9 ->register();
Array Syntax#Copied!
1['type' => 'route_controller', 'value' => 'AppHttpControllersDocsController']
2['type' => 'route_controller', 'value' => '*DocsController', 'operator' => 'LIKE']
AppHttpControllersDocsController). For invokable controllers, the class name is returned without a method suffix.