rosamarsky/laravel-doctrine-odm 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rosamarsky/laravel-doctrine-odm

最新稳定版本:3.0.2

Composer 安装命令:

composer require rosamarsky/laravel-doctrine-odm

包简介

Simple Laravel Doctrine ODM adapter

README 文档

README

A simple Doctrine ODM adapter for Laravel that supports attribute and XML mapping for MongoDB.

Features

  • Supports PHP 8 attributes and XML mappings.
  • Works with Doctrine ODM 3.0+.
  • Laravel service provider for easy integration.
  • Registers custom Carbon type automatically.

Installation

Install via Composer:

composer require rosamarsky/laravel-doctrine-odm

The package auto-registers the service provider, so no manual registration is required.

Configuration

Publish the config file:

php artisan vendor:publish --provider="Rosamarsky\LaravelDoctrineOdm\ServiceProvider" --tag=config

This will create config/doctrine-odm.php.

Set your MongoDB credentials in .env or directly in the config:

MONGO_HOST=127.0.0.1
MONGO_PORT=27017
MONGO_DB=your_database
MONGO_USER=
MONGO_PASS=

Usage

Define Documents

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Carbon\Carbon;

#[ODM\Document(collection: "users")]
class User
{
    #[ODM\Id]
    private string $id;

    #[ODM\Field(type: "string")]
    private string $name;

    #[ODM\Field(type: "string")]
    private string $email;

    #[ODM\Field(type: "carbon")]
    private Carbon $createdAt;

    public function __construct(string $name, string $email)
    {
        $this->name = $name;
        $this->email = $email;
        $this->createdAt = new Carbon();
    }
}

XML mapping is also supported if you configure driver => 'xml' and put your XML files in metadata_dir.

Using DocumentManager

use \Doctrine\ODM\MongoDB\DocumentManager;

class UserController extends AbstractController
{
    public function __construct(private readonly DocumentManager $manager) {}

    public function store(Request $request): User
    {
        $user = new User('Roman Samarsky', 'rosamarsky@gmail.com');

        $this->manager->persist($user);
        $this->manager->flush();

        return $user;
    }
}

License

MIT © Roman Samarsky

统计信息

  • 总下载量: 421
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固