Download the PHP package larawave/logic-as-data without Composer

On this page you can find all versions of the php package larawave/logic-as-data. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package logic-as-data

Logic-as-Data for Laravel

Latest Version on Packagist Total Downloads License

🌟 Introduction

Logic-as-Data is a high-performance, database-driven rules engine designed specifically for Laravel applications.

In modern applications β€” especially in e-commerce marketing and loyalty programs β€” business logic changes faster than code can be deployed. Hardcoding conditional logic (like "If user is Gold AND cart > $100") into your controllers creates technical debt and requires a developer for every minor campaign adjustment.

This package flips the script by allowing you to store complex business logic as structured JSON data in your database.

⚠️ Beta Version
This package is currently in Beta. Expect frequent updates and potential breaking changes until we reach version 1.0.0. Please report any issues or bugs on the GitHub repository.

Why Logic-as-Data?

Whether you are building a dynamic discount engine, a tiered loyalty system, or a complex notification router, Logic-as-Data provides the infrastructure to make your application's logic as flexible as your data.

✨ Key Features

πŸ“‹ Requirements

To use Logic-as-Data, your Laravel application must meet the following requirements:

Note: No frontend dependencies (Node.js/NPM) are required for the host application to use this package. All Admin UI assets are pre-compiled and can be published directly to your public directory.

πŸš€ Installation

The package is designed to be up and running in seconds using an automated installation command. Follow these steps to integrate Logic-as-Data into your Laravel application.

1. Install via Composer

Since the package is currently in Beta, ensure you specify the version or allow beta releases:


2. Run the Automated Installer

We provide a dedicated install command that handles publishing the configuration, migrations, frontend assets and a customizable App-level Service Provider.

During this process, the installer will:


3. Register the Service Provider

To ensure your custom source extractors, operators, target resolvers, evaluators, actions are loaded correctly, you must register the newly published Service Provider in your application.

For Laravel 11 & 12:

Add the provider to bootstrap/providers.php:

For Laravel 10:

Add the provider to the providers array in config/app.php:


4. Verify the Installation

Once installed and registered, you can access the Logic as Data Dashboard to verify that the installation is successful and assets are loading correctly:

πŸ”’ Access Control & Security

By default, the Logic-as-Data dashboard is strictly protected. The package defines a Laravel Gate named viewLogicAsData to prevent unauthorized access to your telemetry logs and logic rules in production.

Default Behavior

In the core service provider, the access is restricted to the local environment only:


Customizing Access

To authorize specific users or roles in production, you should modify the Gate definition inside your published Service Provider located at: app/Providers/LogicAsDataServiceProvider.php

Here are common real-world examples of how to restrict access:

1. Restrict by Admin Email

If you want to give access only to specific team members:

2. Restrict by Role (e.g., Spatie Permissions)

If your application uses a role/permission system, you can check for a specific capability:

3. Combine Environment & User ID

A robust approach that allows local development for everyone but restricts production to a specific Super Admin:

βš™οΈ Configuration

After running the installer, a configuration file will be published to config/logic-as-data.php. You can customize the behavior of the Logic as Data engine and the dashboard here.

Most settings are pre-configured to work with .env variables for easy environment management.

🏠 Dashboard & Routes

Customize how you access the Admin UI.

πŸ“Š Telemetry & Tracing

The telemetry system records every logic evaluation for debugging and auditing.

⚑ Performance (Caching)

Since rules are often evaluated on every request, the package includes an intelligent caching layer.

πŸ—„οΈ Database Tables

If the default table names conflict with your existing database schema, you can rename them here before running the migrations:


πŸ”‘ Environment Variables

You can quickly configure the package by adding these keys to your .env file:

Variable Default Description
LOGIC_AS_DATA_PREFIX admin/logic-as-data Dashboard URL path
LOGIC_AS_DATA_TELEMETRY_ENABLED true Toggle all logging
LOGIC_AS_DATA_TELEMETRY_STRICT auto Throw errors on telemetry fail
LOGIC_AS_DATA_CACHE_ENABLED true Toggle rule caching
LOGIC_AS_DATA_DEV_MODE false Enable Vite HMR for UI development

🧠 Core Concepts

To effectively use Logic-as-Data, it helps to understand the vocabulary of the engine. The package revolves around evaluating a Predicate (a set of conditions) and executing Actions if those conditions are met.

1. Hooks & Context

When you want the engine to run, you dispatch an event to a specific Hook and pass it real-time Context.

2. The Predicate (The Rule)

A Predicate is the actual JSON logic stored in the database. It is evaluated by the PredicateEvaluator and consists of two main parts:

Every single Clause is made up of three distinct parts: a Source, an Operator, and a Target.

A. Source (Extractors)

The Source is the "left hand side" of the equation. It defines what data we are looking at. Sources are resolved using Extractors. For example, the alias user.email uses the LaraWave\LogicAsData\Extractors\UserExtractor to pull the email address from the Context.

B. Operators

The Operator is the comparison engine. It compares the extracted Source against the resolved Target. The package includes dozens of built-in operators mapped in the LogicRegistry, including:

C. Target (Resolvers)

The Target is the "right hand side" of the equation. It defines what we are comparing the Source against. Targets use Resolvers. The most common resolver is core.literal, which allows you to hardcode a value (like checking if an email ends with @example.com). However, targets can also be dynamic, like checking if a user's setting matches a system.config value.

3. Actions

While the engine can be used purely for boolean evaluation (returning true or false), it is also capable of Execution.

If a Predicate successfully passes, the engine can execute an array of Actions. Actions are predefined PHP classes (like LogMessageAction or LogoutAction) that map to a specific alias. They accept parameters defined directly in your JSON.

🧩 Extending the Engine

While Logic-as-Data ships with few built-in source extractors, operators, target resolvers and actions, every application has unique business logic. You will inevitably need to create custom Extractors/Resolvers (e.g., to get a user's loyalty tier) or custom Actions (e.g., to apply a specific discount code).

To make this seamless, the package includes dedicated Artisan generators that scaffold these classes for you, complete with the required metadata() methods for the Admin UI.

Artisan Generators

Run any of the following commands in your terminal to generate a new component. By default, these classes are published to your app/LogicAsData directory.

The Custom Component Workflow

Adding a custom component to your logic engine always follows three simple steps:

Step 1: Generate & Implement

Run the Artisan command and open the generated file (e.g., app/Logic/Extractors/UserLoyaltyExtractor.php). Implement your PHP logic in the primary method (like extract() or execute()).

Step 2: Configure UI Metadata

Inside the generated class, you will see a metadata() method. Update the label, description, and fields array. This ensures your custom component seamlessly appears in the Vue 3 Admin Dashboard with the correct input fields.

Step 3: Register the Component

For the Logic Engine to recognize your new component, you simply add it to the corresponding array in the App-level Service Provider.

When you ran php artisan logic-as-data:install, the package published a dedicated provider to your application at app/Providers/LogicAsDataServiceProvider.php.

Open this file and map your new classes to their JSON aliases:

The Service Provider will automatically loop through these arrays during the boot cycle and register them with the underlying LogicRegistry. Once registered, your business team can immediately start using "user.loyalty_tier" and "cart.apply_discount" in their JSON rules via the Admin UI!

The Two Execution Methods

Because of this architecture, the LogicEngine provides two distinct ways to interact with your rules:

  1. LogicEngine::passes(): Evaluates the predicate. Returns a boolean, but does not execute actions. (Great for "Should I show this button?" checks).
  2. LogicEngine::trigger(): Evaluates the predicate and, if it passes, automatically executes the attached Actions. (Great for automated workflows).

All versions of logic-as-data with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package larawave/logic-as-data contains the following files

Loading the files please wait ...