https://github.com/wolfy-j/lodm
ODM with inheritance and OOP composition for Laravel 5+
https://github.com/wolfy-j/lodm
laravel mongodb odm php spiral
Last synced: over 1 year ago
JSON representation
ODM with inheritance and OOP composition for Laravel 5+
- Host: GitHub
- URL: https://github.com/wolfy-j/lodm
- Owner: wolfy-j
- License: mit
- Created: 2015-10-07T13:41:06.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-08-02T20:07:26.000Z (almost 9 years ago)
- Last Synced: 2024-10-13T13:10:01.968Z (over 1 year ago)
- Topics: laravel, mongodb, odm, php, spiral
- Language: PHP
- Homepage:
- Size: 98.6 KB
- Stars: 21
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
- awesome-laravel - LODM - ODM package for Laravel with native support for MongoDB that supports inheritance, composition, and aggregation, as well as hierarchical data. \[10/12/2015\] (Packages / Database/Eloquent/Models)
- awesome-laravel - LODM - ODM package for Laravel with native support for MongoDB that supports inheritance, composition, and aggregation, as well as hierarchical data. \[10/12/2015\] (Packages / Database/Eloquent/Models)
README
ODM with inheritance and OOP composition for Laravel 5+
========
[](https://packagist.org/packages/spiral/odm)
[](https://packagist.org/packages/spiral/odm)
[](https://travis-ci.org/spiral/odm)
[](https://scrutinizer-ci.com/g/spiral/odm/?branch=master)
[](https://coveralls.io/github/spiral/odm?branch=master)
[Full Documentation](http://spiral-framework.com/guide) | [CHANGELOG](https://github.com/spiral/odm/blob/master/CHANGELOG.md)
LODM module is intended to bring the Spiral ODM component functionality into your Laravel applications. This component provides the ability to manage your MongoDB data in an OOP way using your models compositions and aggregations.
## Installation
Package installation can be performed using the simple composer command
`$ composer require wolfy-j/lodm`.
To include ODM functionality in your application, you have to register the service provider `Spiral\LODM\Laravel\ODMServiceProvider` and CLI command `Spiral\LODM\Commands\SchemaUpdate` in the app.php configure and `ConsoleKernel` accordingly.
The module provides two configuration files which describe the class location directories (by default whole application), the set of connected MongoDB databases (ODM does not use any of Laravel's database functionality) and options that can simplify document creation.
## Documentation
* [MongoDB Databases](https://spiral-framework.com/guide/odm/databases.md)
* [Documents and DocumentEntity](https://spiral-framework.com/guide/odm/entities.md)
* [Accessors and Filters](https://spiral-framework.com/guide/odm/accessors.md)
* [Repositories and Selectors](https://spiral-framework.com/guide/odm/repositories.md)
* [Scaffolding](https://spiral-framework.com/guide/odm/scaffolding.md)
* [Compositions and Aggregations](https://spiral-framework.com/guide/odm/oop.md)
* [Inheritance](https://spiral-framework.com/guide/odm/inheritance.md)
## Examples
```php
class User extends Document
{
const SCHEMA = [
'_id' => \MongoId::class,
'name' => 'string',
'email' => 'string',
'balance' => 'float',
'timeRegistered' => \MongoDate::class,
'tags' => ['string'],
'profile' => Profile::class,
//Aggregations
'posts' => [
self::MANY => Post::class,
['userId' => 'self::_id']
]
];
}
```
```php
protected function indexAction()
{
$u = new User();
$u->name = 'Anton';
$u->email = 'test@email.com';
$u->balance = 99;
$u->save();
dump($u);
}
```
```php
protected function indexAction(string $id, UsersRepository $users)
{
$user = $users->findByPK($id);
if (empty($user)) {
throw new NotFoundException('No such user');
}
dump($user);
}
```
```php
$user = User::findOne();
$user->profile->biography = 'some bio';
$user->profile->facebookUID = 2345678;
$user->sessions->solidState(false);
$user->sessions->push(new Session([
'timeCreated' => new \MongoDate(),
'accessToken' => 'newrandom'
]));
```
## Issues
Please do not open issue tickets in this github project unless they are related to the integration process. Use [Primary Respository](https://github.com/spiral/odm) for ODM related issues.