PHPackages                             pion/laravel-logic-factory - 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. pion/laravel-logic-factory

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

pion/laravel-logic-factory
==========================

The abstract LogicFactory for easier logic classes

v1.1(10y ago)013MITPHP

Since Jan 28Pushed 10y ago1 watchersCompare

[ Source](https://github.com/pionl/laravel-logic-factory)[ Packagist](https://packagist.org/packages/pion/laravel-logic-factory)[ RSS](/packages/pion-laravel-logic-factory/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Laravel Factory logic
=====================

[](#laravel-factory-logic)

A class that support quick creation of logic classes from the LogicFactory. When you need to create a class from a string that represents the Class of the Logic Class.

- Fully unit tested.
- Easy usage.

Instalation
-----------

[](#instalation)

```
composer require pion/laravel-logic-factory

```

Content
-------

[](#content)

- [Usage](#usage)
- [Eloquent Model traits](#eloquent-model-traits)
- [Example](#example)
- [Todo](#todo)

Usage
-----

[](#usage)

You must subclass the LogicFactory and implement own static functions. Full example can be found in tests/Mock/TypeFactory.php

### createLogicList (static)

[](#createlogiclist-static)

Returns a Collection of availiable logic classes. Indexed by the Class name (without namespace) and title as value.

**Example**

```
/**
 * Create an own colleciton of types
 * @return \Illuminate\Support\Collection
 */
static function createLogicList()
{
    return new \Illuminate\Support\Collection([
        "TestType" => "Testing type"
    ]);
}

```

### logicNamespace (static)

[](#logicnamespace-static)

Returns current namespace of the factory subclass to load correct classes.

**Example**

```
/**
 * A namespace where the logic classes are stored. Like
 * __NAMESPACE__."\\Types
 * @return string
 */
static function logicNamespace()
{
    return __NAMESPACE__."\\Types";
}

```

### lists (static)

[](#lists-static)

Ideal to create a select of available types. Ideal to use in database with getLogic in the model

**Example**

```
{!! Form::select("test", TestFactory::lists()->toArray()) !!}

```

### valide (static)

[](#valide-static)

Used to quicky check if the passed logic class string is valide (without namespace). Uses isValide function.

### title (static)

[](#title-static)

Returns the title for given logic class string (uses getTitle function)

Eloquent Model traits
---------------------

[](#eloquent-model-traits)

Ideal for quick usage of the factory in models. Support the caching of the classes and functions for quick accesing of the factory and the final class.

```
/**
 * Returns the logic factory.
 *
 * @param string|null $attribute    the used attribute from the model to use as a class. When null, the default
 * property will be used. Enables multiple logic usage in model.
 *
 * @return LogicFactory
 */
public function getLogicInstance($attribute = null);

/**
 * Returns the logic class from the logic factory
 *
 * @param string|null $attribute    the used attribute from the model to use as a class. When null, the default
 * property will be used. Enables multiple logic usage in model.
 *
 * @return mixed
 */
public function getLogicFactory($attribute = null);

```

### ModelLogicTrait

[](#modellogictrait)

Used for models that has more attributes with logic interface. By passing the attribute you define the correct value to use. You can set (overide \_\_construct method) **logicAttributeName** property for own attribute name to use.

You need to implement the createLogicFactory function and return the own factory. More advance example in tests/Mock/Models/ModelLogic.php

**Example**

```
use ModelLogicTrait;

public function createLogicFactory($classValue, $attributeName)
{
    return new LogicFactory($classValue);
}

```

### ModelSingleLogicTrait

[](#modelsinglelogictrait)

Used when the model has single attribute with logic class. You need to implement only getLogicFactoryClass method.

**Example**

```
use ModelSingleLogicTrait;

public function getLogicFactoryClass()
{
    return TypeFactory::class;
}

```

Example
-------

[](#example)

### Basic example

[](#basic-example)

```
$logic = new TypeFactory("VarcharType");

// returns the class you need
$type = $logic->getLogic();

$type->customMethodYouProvide();

```

### Validation

[](#validation)

```
if (!TypeFactory::valide("VarcharType")) {
	throw new Exception();
}

```

### Title

[](#title)

```
return TypeFactory::title("VarcharType");

```

### Eloquent Model example

[](#eloquent-model-example)

```
/**
 * @var OptionType|null
 */
protected $optionType = null;

protected $fillable = [
	'type'
];

/**
 * @return string
 */
public function getType() {
    return $this->type;
}

/**
 * Returns a type helper
 * @return OptionType|null
 */
public function getTypeHelper()
{
	if (is_null($this->optionType)) {
		$this->optionType = new OptionType($this->getType(), $this);
	}

	return $this->optionType;
}

```

Todo
----

[](#todo)

- refactor to interface
- add automatic file based Logic Class loading from the given logicNamespace (defined as a folder) with some sort of caching.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity64

Established project with proven stability

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 ~0 days

Total

2

Last Release

3758d ago

### Community

Maintainers

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pion-laravel-logic-factory/health.svg)

```
[![Health](https://phpackages.com/badges/pion-laravel-logic-factory/health.svg)](https://phpackages.com/packages/pion-laravel-logic-factory)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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