PHPackages                             butschster/cycle-orm - 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. [Database &amp; ORM](/categories/database)
4. /
5. butschster/cycle-orm

ActiveLibrary[Database &amp; ORM](/categories/database)

butschster/cycle-orm
====================

Cycle ORM integration for the Laravel Framework

v0.6(4y ago)35379[1 issues](https://github.com/butschster/LaravelCycleORM/issues)MITPHPPHP ^7.4|^8.0CI failing

Since Jun 24Pushed 4y ago2 watchersCompare

[ Source](https://github.com/butschster/LaravelCycleORM)[ Packagist](https://packagist.org/packages/butschster/cycle-orm)[ RSS](/packages/butschster-cycle-orm/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (4)Dependencies (14)Versions (5)Used By (0)

Cycle ORM integration for the Laravel Framework
===============================================

[](#cycle-orm-integration-for-the-laravel-framework)

[![laracycle](https://user-images.githubusercontent.com/773481/86586434-8c675700-bf90-11ea-836c-59b7485f6a8f.png)](https://user-images.githubusercontent.com/773481/86586434-8c675700-bf90-11ea-836c-59b7485f6a8f.png)

[![Latest Stable Version](https://camo.githubusercontent.com/6ba3ed48926578a5aee41338ff3a7c2a9986b3ad3da72f7d1dc1862d2fdddfd5/68747470733a2f2f706f7365722e707567782e6f72672f627574736368737465722f6379636c652d6f726d2f762f737461626c65)](https://packagist.org/packages/butschster/cycle-orm) [![Total Downloads](https://camo.githubusercontent.com/bc607cf7ce2d1b886b5cc1cb0fd48ce9a3ee29b5353470b7fa91a0610582fe28/68747470733a2f2f706f7365722e707567782e6f72672f627574736368737465722f6379636c652d6f726d2f646f776e6c6f616473)](https://packagist.org/packages/butschster/cycle-orm) [![License](https://camo.githubusercontent.com/f2240cb7ef60b0e2587d2c39c785fc688842699e4e77ac24f5971cdb7768b2a5/68747470733a2f2f706f7365722e707567782e6f72672f627574736368737465722f6379636c652d6f726d2f6c6963656e7365)](https://packagist.org/packages/butschster/cycle-orm)

Cycle is a PHP DataMapper ORM and Data Modelling engine designed to safely work in classic and daemonized PHP applications (like RoadRunner). The ORM provides flexible configuration options to model datasets, a powerful query builder, and supports dynamic mapping schemas. The engine can work with plain PHP objects, support annotation declarations, and proxies via extensions.

Full information -

### Requirements

[](#requirements)

- Laravel 7.x
- PHP 7.4 and above

Installation and Configuration
------------------------------

[](#installation-and-configuration)

From the command line run

```
composer require butschster/cycle-orm
```

Optionally you can register the EntityManager, Transaction and/or ORM facade:

```
'DatabaseManager' => Butschster\Cycle\Facades\DatabaseManager::class,
'Transaction' => Butschster\Cycle\Facades\Transaction::class,
'ORM' => Butschster\Cycle\Facades\ORM::class,
'EntityManager' => Butschster\Cycle\Facades\EntityManager::class,
```

### Env variables

[](#env-variables)

```
DB_CONNECTION=postgres
DB_HOST=127.0.0.1
DB_PORT= # Default port 5432
DB_DATABASE=homestead
DB_USERNAME=root
DB_PASSWORD=

DB_MIGRATIONS_TABLE=migrations # Migrations table name

DB_SCHEMA_SYNC=false # Sync DB schema without migrations
DB_SCHEMA_CACHE=true # Cache DB schema
DB_SCHEMA_CACHE_DRIVER=file # DB schema cache driver

```

### Configuration

[](#configuration)

Publish the config file.

```
php artisan vendor:publish --provider="Butschster\Cycle\Providers\LaravelServiceProvider" --tag=config
```

#### Configure Databases

[](#configure-databases)

The list of available connections and databases can be listed in the `config/cycle.php` - `database` section. For more information see

#### Getting Database Manager ($dbal)

[](#getting-database-manager-dbal)

`DatabaseManager` registered as a singleton container

```
$dbal = $this->app->get(\Spiral\Database\DatabaseManager::class);
// Or
$dbal = $this->app->get(\Spiral\Database\DatabaseProviderInterface::class);
```

**That's it!**

### Console commands

[](#console-commands)

#### php artisan cycle:migrate

[](#php-artisan-cyclemigrate)

Run cycle orm migrations from the directory.

#### php artisan cycle:refresh

[](#php-artisan-cyclerefresh)

Refresh database schema.

Usage
-----

[](#usage)

By default, class locator looks for entities in app folder. You can specify locations in `config/cycle.php` config file.

```
...
'directories' => [
    app_path(),
],
...
```

### Entity Manager

[](#entity-manager)

The EntityManager is the central access point to ORM functionality. It can be used to find, persist and remove entities.

#### Using the EntityManager

[](#using-the-entitymanager)

You can use the facade, container or Dependency injection to access the EntityManager methods

```
EntityManager::persist($entity);

// Or

app(\Butschster\Cycle\Contracts\EntityManager::class)->persist($entity);

// Or

use Butschster\Cycle\Contracts\EntityManager;

class ExampleController extends Controller
{
    protected $em;

    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }
}
```

#### Finding entities

[](#finding-entities)

Entities are objects with identity. Their identity has a conceptual meaning inside your domain. In a CMS application each article has a unique id. You can uniquely identify each article by that id.

```
$article = EntityManager::findByPK('App\Article', 1);
$article->setTitle('Different title');

$article2 = EntityManager::findByPK('App\Article', 1);

if ($article === $article2) {
    echo "Yes we are the same!";
}
```

#### Persisting

[](#persisting)

By passing the entity through the persist method of the EntityManager, that entity becomes MANAGED, which means that its persistence is from now on managed by an EntityManager.

```
$article = new Article;
$article->setTitle('Let\'s learn about persisting');

EntityManager::persist($article);
```

#### Deleting

[](#deleting)

An entity can be deleted from persistent storage by passing it to the delete($entity) method.

```
EntityManager::delete($article);
```

### Example

[](#example)

#### User

[](#user)

```
