Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 3 months 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 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-02T20:07:26.000Z (over 7 years ago)
- Last Synced: 2024-10-13T13:10:01.968Z (4 months 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
README
ODM with inheritance and OOP composition for Laravel 5+
========
[![Latest Stable Version](https://poser.pugx.org/spiral/odm/v/stable)](https://packagist.org/packages/spiral/odm)
[![License](https://poser.pugx.org/spiral/odm/license)](https://packagist.org/packages/spiral/odm)
[![Build Status](https://travis-ci.org/spiral/odm.svg?branch=master)](https://travis-ci.org/spiral/odm)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/spiral/odm/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/spiral/odm/?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/spiral/odm/badge.svg?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 = '[email protected]';
$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.