PHPackages                             cornford/logical - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cornford/logical

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cornford/logical
================

An easy way execute logical statements over a none persisted results set in Laravel.

v3.1.0(6y ago)6588MITPHPPHP &gt;=7.2

Since Oct 27Pushed 6y ago1 watchersCompare

[ Source](https://github.com/bradcornford/Logical)[ Packagist](https://packagist.org/packages/cornford/logical)[ RSS](/packages/cornford-logical/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (4)Versions (32)Used By (0)

An easy way execute logical statements over a none persisted results set in Laravel.
====================================================================================

[](#an-easy-way-execute-logical-statements-over-a-none-persisted-results-set-in-laravel)

[![Latest Stable Version](https://camo.githubusercontent.com/79afbe4ad69f3d8505735e33c92a4b4977cfeacd6e4c03ec94ea524884380095/68747470733a2f2f706f7365722e707567782e6f72672f636f726e666f72642f6c6f676963616c2f76657273696f6e2e706e67)](https://packagist.org/packages/cornford/logical)[![Total Downloads](https://camo.githubusercontent.com/96bc99a9f0080a95c9b72e3674ce7953aa4280282fb5655bfbd0e68d4a7dfe22/68747470733a2f2f706f7365722e707567782e6f72672f636f726e666f72642f6c6f676963616c2f642f746f74616c2e706e67)](https://packagist.org/packages/cornford/logical)[![Build Status](https://camo.githubusercontent.com/a21033e519e58f01259baa96b84246bf37e7bc142573a1fb5d5b836fcc832ef8/68747470733a2f2f7472617669732d63692e6f72672f62726164636f726e666f72642f4c6f676963616c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bradcornford/Logical)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/c441d1c4b0606f8dcf85bfe131960d005588881e6d31461cea15cd61e6da33eb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f62726164636f726e666f72642f4c6f676963616c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bradcornford/Logical/?branch=master)

### For Laravel 5.x, check [version 2.6.0](https://github.com/bradcornford/Logical/tree/v2.6.0)

[](#for-laravel-5x-check-version-260)

### For Laravel 4.x, check [version 1.6.0](https://github.com/bradcornford/Logical/tree/v1.6.0)

[](#for-laravel-4x-check-version-160)

Think of Logical as an easy way to execute logical statements over a none persisted results set with Laravel, providing a way to reduce a results set against a logical sentence. These include:

- `Logical::setLogicalStatementInstance`
- `Logical::getLogicalStatementInstance`
- `Logical::setInput`
- `Logical::getInput`
- `Logical::setLogic`
- `Logical::getLogic`
- `Logical::execute`
- `Logical::getResults`
- `Logical::reset`

Installation
------------

[](#installation)

Begin by installing this package through Composer. Edit your project's `composer.json` file to require `cornford/logical`.

```
"require": {
    "cornford/logical": "2.*"
}

```

Next, update Composer from the Terminal:

```
composer update

```

Once this operation completes, the next step is to add the service provider. Open `app/config/app.php`, and add a new item to the providers array.

```
'Cornford\Logical\Providers\LogicalServiceProvider',

```

The final step is to introduce the facade. Open `app/config/app.php`, and add a new item to the aliases array.

```
'LogicalFacade'         => 'Cornford\Logical\Facades\Logical',

```

That's it! You're all set to go.

Usage
-----

[](#usage)

It's really as simple as using the Logical class in any Controller / Model / File you see fit with:

`Logical::`

This will give you access to

- [Set Logical Statement Instance](#set-logical-statement-instance)
- [Get Logical Statement Instance](#get-logical-statement-instance)
- [Set Input](#set-input)
- [Get Input](#get-input)
- [Set Logic](#set-logic)
- [Get Logic](#get-logic)
- [Execute](#execute)
- [Get Results](#get-results)
- [Reset](#reset)

### Set Logical Statement Instance

[](#set-logical-statement-instance)

The `setLogicalStatementInstance` method allows a custom Logical Statement Instance to be passed to after construction.

```
Logical::setLogicalStatementInstance(new LogicalStatement);
Logical::setLogicalStatementInstance(new MyLogicalStatement);

```

### Get Logical Statement Instance

[](#get-logical-statement-instance)

The `getLogicalStatementInstance` method returns the set Logical Statement Instance.

```
Logical::getLogicalStatementInstance();
Logical::getLogicalStatementInstance()->defineCustomStatement('test', function ($input, $expected) { return true; });

```

### Set Input

[](#set-input)

The `setInput` method sets a input array set.

```
Logical::setInput([['name' => 'tom'], ['name' => 'jerry']]);

```

### Get Input

[](#get-input)

The `getInput` method returns the set input array set.

```
Logical::getInput();

```

### Set Logic

[](#set-logic)

The `setLogic` method allows a logic statement string to be set. The available logical methods are within the Logical Statement class.

```
Logical::setLogic('where("name").equals("tom")');

```

### Get Logic

[](#get-logic)

The `getLogic` method returns the set logic statement string.

```
Logical::getLogic();

```

### Execute

[](#execute)

The `execute` method decodes the logic string into callable methods and then executes those methods against the input array.

```
Logical::execute();

```

### Get Results

[](#get-results)

The `getResults` method returns the items matching the logic statement sting from the input array set.

```
Logical::getResults();

```

### Reset

[](#reset)

The `reset` method resets input, logic and results.

```
Logical::reset();

```

Building Logic Statement Strings
--------------------------------

[](#building-logic-statement-strings)

Logic statement strings are built by defining as follows:

- A field that should be conditioned against `where("field")`.
- A statement method that can executed `where("field").equals("tom")`.
- A conditions and methods are separated with a `.`.
- Multiple conditions and methods can be attached using `AND` or `OR` such as `where("field").equals("tom").OR.where("field").equals("jerry")`.

### Logic Statement String Methods

[](#logic-statement-string-methods)

Below is a list of available logic statement string methods:

- [Equals](#equals)
- [Is Length](#is-length)
- [Is](#is)
- [Contains](#contains)
- [Contained In](#contained-in)
- [In](#in)
- [Between](#between)
- [Null](#null)
- [Less Than](#less-than)
- [Greater Than](#greater-than)
- [Less Than Or Equal](#less-than-or-equal)
- [Greater Than Or Equal](#greater-than-or-equal)
- [Starts With](#starts-with)
- [Ends With](#ends-with)

### Equals

[](#equals)

The `equals` method returns true if the input value equals the expected value.

```
equals(1)

```

The `notEquals` method returns true if the input value doesn't equals the expected value.

```
notEquals(1)

```

### Is Length

[](#is-length)

The `isLength` method returns true if the input value equals the expected length value.

```
isLength(1)

```

The `isNotLength` method returns true if the input value doesn't equals the expected length value.

```
isNotLength(1)

```

### Is

[](#is)

The `is` method returns true if the input value is the same type the expected value.

```
is("boolean")

```

The `isNot` method returns true if the input value isn't the same type the expected value.

```
isNot("boolean")

```

### Contains

[](#contains)

The `contains` method returns true if the input value contains the expected value.

```
contains("o")

```

The `notContains` method returns true if the input value doesn't contain the expected value.

```
notContains("o")

```

### Contained In

[](#contained-in)

The `containedIn` method returns true if the input value contains an item of the expected values.

```
containedIn(["a", "b", "c"])

```

The `notContainedIn` method returns true if the input value doesn't contain an item of the expected values.

```
notContainedIn(["a", "b", "c"])

```

### In

[](#in)

The `in` method returns true if the input value is an item of the expected values.

```
in(["a", "b", "c"])

```

The `notIn` method returns true if the input value is not an item of the expected values.

```
notIn(["a", "b", "c"])

```

### Between

[](#between)

The `between` method returns true if the input value is between the expected values.

```
between(1, 10)

```

The `notBetween` method returns true if the input value is not between the expected values.

```
notBetween(1, 10)

```

### Null

[](#null)

The `null` method returns true if the input value is null.

```
null()

```

The `notNull` method returns true if the input value is not null.

```
notNull()

```

### Less Than

[](#less-than)

The `lessThan` method returns true if the input value is less than the expected value.

```
lessThan(10)

```

The `notLessThan` method returns true if the input value is not less than the expected value.

```
notLessThan(10)

```

### Greater Than

[](#greater-than)

The `greaterThan` method returns true if the input value is greater than the expected value.

```
greaterThan(10)

```

The `notGreaterThan` method returns true if the input value is not greater than the expected value.

```
notGreaterThan(10)

```

### Less Than Or Equal

[](#less-than-or-equal)

The `lessThanOrEqual` method returns true if the input value is less than or equal to the expected value.

```
lessThanOrEqual(10)

```

The `notLessThanOrEqual` method returns true if the input value is not less than or not equal to the expected value.

```
notLessThanOrEqual(10)

```

### Greater Than Or Equal

[](#greater-than-or-equal)

The `greaterThanOrEqual` method returns true if the input value is greater than or equal to the expected value.

```
greaterThanOrEqual(10)

```

The `notGreaterThanOrEqual` method returns true if the input value is not greater than or not equal to the expected value.

```
notGreaterThanOrEqual(10)

```

### Starts With

[](#starts-with)

The `startsWith` method returns true if the input value starts with the expected value.

```
startsWith('hello')

```

The `notStartsWith` method returns true if the input value doesn't start with the expected value.

```
notStartsWith('hello')

```

### Ends With

[](#ends-with)

The `endsWith` method returns true if the input value ends with the expected value.

```
endsWith('goodbye')

```

The `notEndsWith` method returns true if the input value doesn't end with the expected value.

```
notEndsWith('goodbye')

```

### License

[](#license)

Logical is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~66 days

Recently: every ~145 days

Total

30

Last Release

2300d ago

Major Versions

v1.3.0 → v2.1.02016-05-10

v1.3.2 → v2.1.22016-05-31

v1.4.0 → v2.4.02017-06-05

v1.5.0 → v2.6.02018-06-27

v1.6.0 → v3.0.02019-11-12

PHP version history (2 changes)v1.0.0PHP &gt;=5.4.0

v3.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/fcf41bf377df077c60272fea95b86b221e6923caa6f4075a519ac161186534ed?d=identicon)[bradcornford](/maintainers/bradcornford)

---

Top Contributors

[![bradcornford](https://avatars.githubusercontent.com/u/2913887?v=4)](https://github.com/bradcornford "bradcornford (8 commits)")

---

Tags

laravelresultslogicsortedstatementexecutionlogicalpersisted

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cornford-logical/health.svg)

```
[![Health](https://phpackages.com/badges/cornford-logical/health.svg)](https://phpackages.com/packages/cornford-logical)
```

###  Alternatives

[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[ringierimu/state-workflow

Laravel State Workflow provide tools for defining and managing workflows and activities with ease.

3251.1k](/packages/ringierimu-state-workflow)[stephenjude/filament-blog

Filament Blog Builder

20317.8k](/packages/stephenjude-filament-blog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
