codesleeve / holloway
Holloway:在Illuminate Database包之上构建的datamapper。
dev-master
2024-07-08 13:55 UTC
Requires
- php: >= 8.1
- illuminate/database: ^8.0|^9.0|^10.0
- illuminate/events: ^8.0|^9.0|^10.0
- illuminate/pagination: ^8.0|^9.0|^10.0
- laravel/legacy-factories: ^1.1
Requires (Dev)
- doctrine/instantiator: ~1.4.0
- fakerphp/faker: ^1.9.1
- mockery/mockery: ^1.4.2
- phpunit/phpunit: ^8.5.8|^9.3.3
- vlucas/phpdotenv: ^5.6
This package is auto-updated.
Last update: 2024-09-08 14:23:18 UTC
README
Holloway是对datamapper模式(Fowler)的松散实现。它是一个基于illuminate/database
包的ORM,这个包也是Laravel实现Active Record:Eloquent所使用的相同包。因此,Holloway映射器可以用来从数据库中检索结果,类似于使用Eloquent模型的方式。然而,从这个映射器返回的实体与底层数据库完全解耦,可以设计成你希望它们工作的方式。
为什么要使用这个包?
总有一天,你可能在Laravel应用中需要不可破坏的领域对象(始终不允许存在于无效状态的实体)。如果你希望使用你熟悉和喜爱的查询构建器语法来查询这些对象,Holloway可能对你有所帮助。
关系
自定义多对多关系示例
$this->customMany('stickyNotes', function ($query, Collection $clientServices) { return $query->from('sticky_notes') ->select('sticky_notes.*', 'client_service_sticky_notes.client_service_id') ->join('client_service_sticky_notes', 'sticky_notes.id', '=', 'client_service_sticky_notes.sticky_note_id') ->whereIn('client_service_sticky_notes.client_service_id', $clientServices->pluck('id')) ->get(); }, function (stdClass $clientService, stdClass $stickyNote) { return $clientService->id == $stickyNote->client_service_id; }, StickyNote::class);