symfony/expression-language
Symfony ExpressionLanguage provides an engine to compile and evaluate one-line expressions that return values (often booleans). Use it to embed simple, safe business rules and conditions in your app, with support for custom functions and variables.
Dynamic Business Logic: Enable non-technical teams (e.g., product, marketing) to configure rules via admin panels (e.g., Laravel Nova, Filament) without code deployments. Examples:
'user.subscription.tier >= 2 && user.country === "EU" && date.between("2024-01-01", "2024-12-31")'.'order.total > 100 && user.isFirstTimeBuyer()').workflow_rules table (e.g., 'status === "reviewed" && (manager_approved || team_lead_approved)').Build vs. Buy Decision:
Roadmap Priorities:
eval() risks.Laravel-Specific Use Cases:
if chains in App\Policies\UserPolicy with expressions stored in a database.'user.hasPermission("access_dashboard") && request.path !== "/admin/backup"').validation_rules table (e.g., 'document_type in ["passport", "driver_license"] && document.expiresAfter(date.today())').'feature_enabled && user.isBetaTester() && user.region === "NA"') via a feature_flags table.'order.status === "pending" && payment.processed()').eval() risks while supporting dynamic logic. The package compiles expressions to PHP and supports variable whitelisting.'Allow if user.department === "finance" && request.path.startsWith("/payments")').'Require document_type === "passport" || document_type === "driver_license" && document.expiresAfter(date.today())').'Enable for user.subscription.tier >= 2 && user.country === "US" && date.isWeekday()').'Route to manager if order.amount > 1000 && user.isNewCustomer()').if ($user->isAdmin())). Use native PHP if/else or Laravel’s built-in helpers (e.g., Gate::forUser()).*"This package eliminates bottlenecks between product teams and engineering by enabling self-service rule management. Here’s how it drives value:
Key Benefits:
'Discount 20% if user.visited > 3 && cart.total > 50') via a CMS—no dev cycles.'Enable dark mode for users in EU') without deployments.if chains in policies or middleware. Rules live in configurable tables, not code.UserPolicy logic with a single database row.eval() risks: Expressions compile to PHP and run in a sandboxed environment with variable whitelisting.Use Cases to Pilot:
'First-time buyers get 15% off').'Edit content if user.role === "editor" && content.status === "draft"').Risk Mitigation:
user, request, date).ROI: Weeks saved per year in rule updates, with zero increase in security risk."
*"This is a secure, high-performance alternative to custom expression parsers or eval(). Here’s why it’s a smart choice for Laravel:
Technical Advantages:
'user.hasPermission("edit_post") && post.publishedAt < date.today()' compiles to static PHP, not dynamic code.public function update(UpdateUserRequest $request) with:
$expression = 'user.canEditProfile() && request.hasValidSignature()';
if (!$this->expressionLanguage->evaluate($expression, ['user' => $user, 'request' => $request])) {
abort(403);
}
eval(): Compiled to safe PHP code.user, request, date).?. operator to avoid runtime errors.How can I help you explore Laravel packages today?