wolfy-j/lodm

此软件包最新版本(v0.9.6)没有提供许可证信息。

Laravel ODM 模块使用 Spiral ODM 组件。

v0.9.6 2017-08-02 20:06 UTC

This package is auto-updated.

Last update: 2024-08-29 03:31:29 UTC


README

Latest Stable Version License Build Status Scrutinizer Code Quality Coverage Status

完整文档 | 变更日志

LODM 模块旨在将 Spiral ODM 组件功能引入您的 Laravel 应用程序。此组件允许您使用模型组合和聚合以面向对象的方式管理 MongoDB 数据。

安装

可以使用简单的 composer 命令安装软件包:$ composer require wolfy-j/lodm

为了将 ODM 功能包含到您的应用程序中,您需要在 app.php 配置中注册服务提供者 Spiral\LODM\Laravel\ODMServiceProvider 和 CLI 命令 Spiral\LODM\Commands\SchemaUpdate

该模块提供了两个配置文件,描述了类位置目录(默认为整个应用程序)、连接的 MongoDB 数据库集合(ODM 不使用 Laravel 的任何数据库功能)以及简化文档创建的选项。

文档

示例

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']
    ]
  ];
}
protected function indexAction()
{
    $u = new User();
    $u->name = 'Anton';
    $u->email = 'test@email.com';
    $u->balance = 99;
    $u->save();

    dump($u);
}
protected function indexAction(string $id, UsersRepository $users)
{
    $user = $users->findByPK($id);
    if (empty($user)) {
        throw new NotFoundException('No such user');
    }

    dump($user);
}
$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'
]));

问题

除非与集成过程相关,否则请不要在此 github 项目中打开问题票据。对于 ODM 相关问题,请使用 主要仓库